4

Is there any way to provide a different node ID per language for the front page setting in Drupal 8?

We need a different front page for a specific language. In Drupal 7, this was easy.

3 Answers 3

6

Technically, the config override API that config translation uses allows any kind of override of configuration.

The core config translation however only does translation, meaning it only allows to change things that are classified as user-facing texts and not technical strings.

What you want is usually referred to as localization, changing things based the language that isn't actually a "translation". There is a core issue to better support this, https://www.drupal.org/node/2275865, but it hasn't been updated in quite some time.

There are a few possible workarounds, though:

  • Since you mention nodes, in Drupal 8, translations of nodes have the same ID/URL. That means you could have your different front pages as translations of the same node. That would be problematic if you use Paragraphs for example, as that doesn't currently support translatable fields, so you'd be forced into the same structure.

  • You could use Page Manager to have different front pages (there is a per-language constraint necessary, which has a patch but has not yet been committed) or even just a view that selects a node based on a certain condition (like filtered by language of a certain type).

  • A custom callback that displays a certain node based on a bit of code.

Update:

4 years later, I had this use case too and still no activity on the core issue. As a workaround, I altered the config schema and made the front_page a label type to be able to translate it. Not fully tested yet, so beware of dragons:

function custom_config_schema_info_alter(&$definitions) {
  // Change the front page type to label so that it can be translated.
  $definitions['system.site']['mapping']['page']['mapping']['front']['type'] = 'label';
}
3
  • Thanks Berdir for the reply. I'm aware of the translation of nodes being the same id, that's exactly the reason for the question - one of the issues being Paragraphs ;) I was indeed thinking along the lines of custom code, but was hoping for a solution in D8 that I overlooked :-p I found a workaround for my problem for this project, but will look into Page Manager for future projects.
    – tijsdb
    Commented Dec 13, 2016 at 9:33
  • @tijsdb Please share your workaround. Commented Mar 30, 2017 at 12:22
  • @KariKääriäinen for this particular project we were able to sort it with the same node eventually. But for other projects I'd follow the answer from Berdir, and use a view which loads 1 node for the active language, or a custom piece of code, redirecting to the right node depending on the language.
    – tijsdb
    Commented Apr 10, 2017 at 13:01
2

Another way to have a homepage per language, or just about any config override per language is to use config override system. I created a ticket in config_override module to add language overrides support and there is a patch attached: https://www.drupal.org/node/2914987

In short, you would be able to create a folder in your codebase with language overrides, where each language will have it's own subfolder and config override will merge config keys from language overrides with the active configuration.

Example of usage: Include language_override config key in settings.php

$config_directories['language_override'] = '../config_override/language';

Place an override file in 'language_override' folder following core's config_translation structure: [language_override]/en/system.site.yml

page:
  front: /node/123

The patch is in review, but you could install the module and apply the patch easily to get this feature.

1

Make a view that provides a block for each language. Master has no output, Content: ID (< 1).

For Language set Rendering Language: Content language of view row (default).

If you want to display a full node on some language's front page, use Format -> Show: Content | Full content, and for Filter criteria use Content: ID (= 123).

Create a node with no content. Make this node your front page in Basic Site Settings -> Default front page. Translate this node for all languages.

Place the blocks at Content region, no title, configure them with language restriction and with Pages restriction, show only on the node you set as your front page.

If you are displaying a full node on one some blocks, include the title in block configuration. The title being shown then is not the node title, but the block title. This will be h2, that needs to be styled like h1.

This is trickier than I remembered, but possible.

1
  • 1
    I used this answer on my D8 multilingual site today. Thanks!
    – SuperTony
    Commented Jul 5, 2017 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.