The D7 language types needs to be migrated to D8. In D8, the language.types configuration by default looks like this:

all:
  - language_interface
  - language_content
  - language_url
configurable:
  - language_interface
negotiation:
  language_content:
    enabled:
      language-interface: 0
  language_url:
    enabled:
      language-url: 0
      language-url-fallback: 1
  language_interface:
    enabled:
      language-url: 0

Here's a quick explanation of each key:

  • all: Lists all the language types.
  • configurable: Lists all the configurable language types.
  • negotiation: For each language types, it lists which negotiation methods are enabled. In addition to the enabled key, each language types can also contain method_weights, which lists the weights of the methods.

In D7, all those settings are spread across multiple variables:

  • language_types
  • language_negotiation_language
  • language_negotiation_language_content
  • language_negotiation_language_url
  • locale_language_providers_weight_language
  • locale_language_providers_weight_language_content (optional)
  • locale_language_providers_weight_language_url (optional)

The language_types variable contains an array of the language types as the keys and booleans as the values, indicating if they are configurable or not.
The language_negotiation_* variables contain arrays of the negotiation methods enabled for that language type.
The locale_language_providers_weight_* variables contain arrays of the negotiation method weights.

Another thing to know is that the negotiation method names are not the same in D7 an D8. In D7 they are prefixed by 'locale_' and in D8 the are prefixed with 'language_'.

The Drupal 6 (and to some degree Drupal 7) counterpart to this is #2225293: Migrate D6 and D7 language negotiation settings, which migrates the global negotiation configurations (eg. domains and prefixes) for both Drupal 6 and 7; and also creates a hardwired structure similar to this for Drupal 6, because the language flexibility is much less versatile there.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sidharthap’s picture

Status: Active » Needs review
FileSize
3.85 KB

Here is my first try to work on the migrate project. I'm not sure if I've done it correctly. Please suggest.

benjy’s picture

Hi @siharthap, that looks pretty good. We're just waiting on this patch: https://www.drupal.org/node/2410625

Which will automate all the dumps for D7 and then we're going to start full speed on the D7 migrate path.

sidharthap’s picture

Thank You @benjy.

jcost’s picture

Project: IMP » Drupal core
Version: » 8.0.x-dev
Component: Code » migration system
Status: Needs review » Needs work

Will need to be submitted again to Core since moving from sandbox.

quietone’s picture

I've completed moving this to the language module and it's running fine locally.

But I can't find variable 'language_interface' in D7, where is it defined?

What about the other language variables; language_count, language_negotiation_language, language_negotiation_language_content and language_negotiation_language_url? Are these to be migrated as well?

quietone’s picture

Status: Needs work » Needs review
FileSize
3.68 KB
6.5 KB

Accidentally lost my previous works (too many distractions today). So here is a quick reroll, done just before going to bed. It needs more work and I'm too tired to do so now. But, let's see what testbot finds.

quietone’s picture

Change parent issue from the duplicate to the current one.

quietone’s picture

Reroll remove unused use statements

Status: Needs review » Needs work

The last submitted patch, 8: 2353709-8.patch, failed testing.

quietone’s picture

Status: Needs work » Needs review
FileSize
3.56 KB
528 bytes

Not sure how I messed up that edit.

phenaproxima’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/language/migration_templates/d7_language_types.yml
    @@ -0,0 +1,25 @@
    +  'negotioation/language_url/enabled/language_url':
    +    plugin: static_map
    +    source: language_url
    +    map:
    +      0: FALSE
    +      1: TRUE
    

    No need for static_map; IIRC the config system will cast 0 and 1 to boolean, based on the config schema.

  2. +++ b/core/modules/language/migration_templates/d7_language_types.yml
    @@ -0,0 +1,25 @@
    +  'negotioation/language_url/enabled/language_content':
    +    plugin: static_map
    +    source: language_content
    +    map:
    +      0: FALSE
    +      1: TRUE
    

    Ditto.

  3. +++ b/core/modules/language/src/Tests/Migrate/d7/MigrateLanguageTypesTest.php
    @@ -0,0 +1,43 @@
    +/**
    +  * Tests migration of language variables into configuration.
    

    Nit: There's an extra space here, at the beginning of the line.

  4. +++ b/core/modules/language/src/Tests/Migrate/d7/MigrateLanguageTypesTest.php
    @@ -0,0 +1,43 @@
    + */
    +
    +class MigrateLanguageTypesTest extends MigrateDrupal7TestBase {
    

    Nit: There's an extra line between the doc block and the class.

  5. +++ b/core/modules/language/src/Tests/Migrate/d7/MigrateLanguageTypesTest.php
    @@ -0,0 +1,43 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    +  public static $modules = ['language'];
    

    Nit: Need a blank line between the class declaration and this doc comment.

  6. +++ b/core/modules/language/src/Tests/Migrate/d7/MigrateLanguageTypesTest.php
    @@ -0,0 +1,43 @@
    +    $config = \Drupal::config('language.settings');
    

    Should be $this->config().

quietone’s picture

Status: Needs work » Needs review
FileSize
3.56 KB

Thx phenaproxima.
1-6 fixed. No interdiff because of Variable.php.

Status: Needs review » Needs work

The last submitted patch, 12: 2353709-12.patch, failed testing.

phenaproxima’s picture

Thank you, config schema checker :) Looks like "negotiation" is misspelled in the migration...

quietone’s picture

Status: Needs work » Needs review
FileSize
3.59 KB
1.59 KB

It's more than a typo, as this failing patch will show.

phenaproxima’s picture

+++ b/core/modules/language/src/Tests/Migrate/d7/MigrateLanguageTypesTest.php
@@ -0,0 +1,42 @@
+    $this->assertIdentical(0, $config->get('negotiation.language_url.enabled.language-url'));
+    $this->assertIdentical(0, $config->get('negotiation.language_content.enabled.language-interface'));

It looks like these are not asserting the values that are in the dump files...?

Status: Needs review » Needs work

The last submitted patch, 15: 2353709-15.patch, failed testing.

The last submitted patch, 15: 2353709-15.patch, failed testing.

phenaproxima’s picture

Issue tags: +Barcelona2015
quietone’s picture

Revisiting this and there is confusion on the source and the destination.

The IS identifies 3 variables to migrate:

  1. 'language_interface' => 'configurable.language_interface'. But when I grep D7 for 'language_interface' no instances are returned.
  2. 'language_content' => 'configurable.language_content'. But language.types.configurable contains only one item, language_interface.
  3. 'language_url' => 'configurable.language_content'. Same problem as #2.

And here is the current test data for the D7 variable, language_types.
a:3:{s:8:"language";b:1;s:16:"language_content";b:0;s:12:"language_url";b:0;}

So, what are the configuration destinations for 'language', 'language_content' and 'language url'?

phenaproxima’s picture

Turns out these variables do not exist in Drupal 7; instead, they refer to the complex language_negotiation_* variables, which are complicated enough to need their own migrations -- possibly a set of migrations. They pack a lot of data into a single variable, which is unpacked in the Drupal 8 language.types config object.

quietone’s picture

Turns out these variables do not exist in Drupal 7

Which variables are you referring to?

This definitely exists in D7:
language_types : a:3:{s:8:"language";b:1;s:16:"language_content";b:0;s:12:"language_url";b:0;}

quietone’s picture

quietone’s picture

Issue summary: View changes
quietone’s picture

Removed tag.

quietone’s picture

Issue tags: +migrate-d7-d8

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

maxocub’s picture

Assigned: Unassigned » maxocub
Issue tags: +D8MI, +sprint

I think there's five D7 variables that we need here:

  1. language_negotiation_language who lists negotiation methods for the interface (language_interface in D8)
  2. language_negotiation_language_content who list negotiation methods for the content
  3. language_negotiation_language_url who lists negotiation methods for the url
  4. language_types who specifies which of the three language types above are configurable
  5. locale_language_providers_weight_language who contains the weight of the negotiation methods

I've been working on the D6 version of this issue (#2225293: Migrate D6 and D7 language negotiation settings), so I might give it a try.

Gábor Hojtsy’s picture

@maxocub: yeah that analysis seems fine, the D7 negotiation settings are similar but a bit more limited than Drupal 8, so the migration is more 1-1 with Drupal 8 than Drupal 6, where you need to generate a whole bunch of things for D8.

maxocub’s picture

@Gábor Hojtsy: In D7, the negotiation methods for language_content and language_url are fixed and non-configurable. Could we just assume they still are and use default values in the migration (like we did with D6) or do we migrate them in case someone altered them of added new ones?

I ask because it's a bit complicated to migrate them since they don't have the same names (locale-url instead of language-url, language-default instead of language-selected, etc.) and are spread across a few variables. I I haven't found a way to use the existing plugins.

Also, if someone altered and/or added new language types, should we try to see if the variables "locale_language_providers_weight_$type" exist?

iMiksu’s picture

Issue tags: +Needs reroll
anish.a’s picture

The file core/modules/migrate_drupal/src/Tests/Table/d7/Variable.php is removed at following commit. Reroll is not trivial.

commit 00d4deb86f8b56c3f8a2287e3f8cc17319d47cf6
Author: webchick <drupal@webchick.net>
Date:   Fri Oct 2 18:15:03 2015 -0700

    Issue #2568203 by phenaproxima, mikeryan: Remove migrate-db.sh in favor of core tools
maxocub’s picture

I'm working on a reroll, and I'm starting from scratch.

Gábor Hojtsy’s picture

1. Migrating contrib types, I don't think we can do in the core migration, so I would not try to do that.
2. language-default was not configurable in drupal 7, so we can assume that it is a fixed thing and migrate to language-selected with a setting tied to default language
3. language_content is definitely not fixed, if you had entity_translation installed in Drupal 7
4. Re language_url, I don't know if there is a contrib module that makes it configurable, I don't think not migrating it from the variables is easier since we need to migrate the two other types, and language_url can consist of settings for the same types, so can use the same migrations(?)

I think those were all the questions? Hopefuly helpful :)

maxocub’s picture

Title: Variable to config: language.types [d7] » Variables to config: language.types [d7]
Version: 8.2.x-dev » 8.3.x-dev
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs reroll, -Needs issue summary update +Needs tests
FileSize
8.51 KB

Here's a new patch. I haven't included an interdiff since I started from scratch.

I haven't found a way to use existing process plugins.

I will wait for reviews before adding unit tests for the new plugins.

Status: Needs review » Needs work

The last submitted patch, 36: 2353709-36.patch, failed testing.

maxocub’s picture

Status: Needs work » Needs review
FileSize
9.18 KB
690 bytes
phenaproxima’s picture

Assigned: maxocub » phenaproxima

Assigning to myself for review.

phenaproxima’s picture

Status: Needs review » Needs work

This is looking pretty good, but the new process plugins need tests.

  1. +++ b/core/modules/language/src/Plugin/migrate/process/LanguageNegotiation.php
    @@ -0,0 +1,88 @@
    +    $methods = array_keys($value[0]);
    +    $weights = $value[1];
    

    Can we check that $value is an array and throw a MigrateException if it isn't?

  2. +++ b/core/modules/language/src/Plugin/migrate/process/LanguageNegotiation.php
    @@ -0,0 +1,88 @@
    +        $new_value = 'language-selected';
    +        break;
    

    For each of these cases, can we just return the value directly instead of setting $new_value and breaking? I think it would be a little cleaner that way.

  3. +++ b/core/modules/language/src/Plugin/migrate/process/LanguageTypes.php
    @@ -0,0 +1,35 @@
    +    if (array_key_exists('language', $value)) {
    

    Before this, let's check that $value is an array and throw MigrateException if not.

  4. +++ b/core/modules/language/src/Plugin/migrate/process/LanguageTypes.php
    @@ -0,0 +1,35 @@
    +    if (isset($this->configuration['filter_configurable']) && $this->configuration['filter_configurable']) {
    

    Should be if (!empty($this->configuration['filter_configurable'])).

maxocub’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
13.85 KB
8.64 KB

Made the changes from #40 and added unit tests.

Gábor Hojtsy’s picture

Reviewed for the migration mappings, it all looks good for what it needs to do. Also confirmed that the Drupal 6 part of this is covered in #2225293: Migrate D6 and D7 language negotiation settings and the missing elements for Drupal 7 language negotiation are there too, so these two issues are complimentary to solve all the core language negotiation setting migrations from both Drupal 6 and 7.

The last submitted patch, 1: 2353709-language-types-1.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 635e4ee to 8.3.x and 641e529 to 8.2.x. Thanks!

Committed to 8.2.x because migrate_drupal is still experimental.

  • alexpott committed 635e4ee on 8.3.x
    Issue #2353709 by quietone, maxocub, sidharthap, phenaproxima, Gábor...

  • alexpott committed 641e529 on 8.2.x
    Issue #2353709 by quietone, maxocub, sidharthap, phenaproxima, Gábor...
Gábor Hojtsy’s picture

Issue tags: -sprint

Yay, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

maxocub’s picture