Suggestion: add these people from the older duplicate issue to the commit message (for opening the issue, and steps to reproduce):
steelsector, matsbla, SiliconMind, vodde83

Problem/Motivation

The configuration of the language types are reset when another module is installed.

Proposed resolution

Not known yet.

Remaining tasks

Identify the cause and find a solution.

when this is committed, unpostpone #2623788: updateConfiguration() should be able to override configurable of language types when modules are installed or uninstalled

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#49 37-47-interdiff.txt1.75 KBMaouna
#49 language-type_reset-2618040-47.patch4.05 KBMaouna
#49 language-type_reset-2618040-47-testsonly.patch3.16 KBMaouna
#43 interdiff.2618040.34.37.txt810 bytesYesCT
#43 language-type_reset-2618040-37.patch3.36 KBYesCT
#43 language-type_reset-2618040-37-testsonly.patch2.44 KBYesCT
#22 language-type_reset-2618040-22.test.patch2.27 KBplach
#22 language-type_reset-2618040-22.interdiff.txt3.5 KBplach
#22 language-type_reset-2618040-22.patch3.19 KBplach
#14 2618040.patch2.62 KBcatch
2618040.patch529 bytescatch
2618040.patch529 bytescatch
#11 2618040.patch529 bytescatch
#4 2-4-interdiff.txt774 bytesMaouna
#4 2618040-config_lang_type_test_passing.patch2.22 KBMaouna
#2 2618040-config_lang_type_failing.patch2.11 KBMaouna
#34 language-type_reset-2618040-34.patch3.35 KBplach
#34 language-type_reset-2618040-34.interdiff.txt4.72 KBplach
#34 language-type_reset-2618040-34.test.patch2.44 KBplach
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Maouna created an issue. See original summary.

Maouna’s picture

Here is a test, that demonstrates the problem. First language_content is set as configurable, but after installing the field module, this is not the case anymore.

Maouna’s picture

Status: Needs work » Needs review
Maouna’s picture

It is interesting that the test passes if I replaced the content_translation module by language_test.

Maouna’s picture

So, my guess is that the cause of this bug lies in the different implementations of hook_language_types_info_alter():

function language_test_language_types_info_alter(array &$language_types) {
  if (\Drupal::state()->get('language_test.content_language_type')) {
    $language_types[LanguageInterface::TYPE_CONTENT]['locked'] = FALSE;
    unset($language_types[LanguageInterface::TYPE_CONTENT]['fixed']);
    // By default languages are not configurable. Make
    // LanguageInterface::TYPE_CONTENT configurable.
    $config = \Drupal::configFactory()->getEditable('language.types');
    $configurable = $config->get('configurable');
    if (!in_array(LanguageInterface::TYPE_CONTENT, $configurable)) {
      $configurable[] = LanguageInterface::TYPE_CONTENT;
      $config->set('configurable', $configurable)->save();
    }
  }
}
function content_translation_language_types_info_alter(array &$language_types) {
  // Make content language negotiation configurable by removing the 'locked'
  // flag.

 $language_types[LanguageInterface::TYPE_CONTENT]['locked'] = FALSE;
  unset($language_types[LanguageInterface::TYPE_CONTENT]['fixed']);
}
Maouna’s picture

Or the way the language negotiater is updated after a module installation is not correct:

/**
 * Implements hook_modules_installed().
 */
function language_modules_installed($modules) {
  if (!in_array('language', $modules)) {
    $negotiator = \Drupal::service('language_negotiator');
    $negotiator->updateConfiguration(array());
    $negotiator->purgeConfiguration();
  }
  else {
    // In language_entity_base_field_info_alter() we are altering view/form
    // display definitions to make language fields display configurable. Since
    // this is not a hard dependency, and thus is not detected by the config
    // system, we have to clean up the related values manually.
    foreach (array('entity_view_display', 'entity_form_display') as $key) {
      $displays = \Drupal::entityManager()->getStorage($key)->loadMultiple();
      /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
      foreach ($displays as $display) {
        $display->save();
      }
    }
  }
}
Maouna’s picture

Issue summary: View changes

The last submitted patch, 2: 2618040-config_lang_type_failing.patch, failed testing.

Maouna’s picture

Status: Needs review » Needs work
catch’s picture

Priority: Major » Critical

Since this is easily-reproduced data loss (fortunately configuration rather than content though), bumping to critical.

catch’s picture

Status: Needs work » Needs review
FileSize
529 bytes

Looked through git blame, if it is language_modules_installed(), the last time it was changed was in 2014, and that was a straight port of previous logic which I didn't track down, so looks like the bug has been here for a long time.

Reading the code, this patch might be enough - untested.

catch’s picture

With the test coverage from #2.

The last submitted patch, 11: 2618040.patch, failed testing.

The last submitted patch, 2618040.patch, failed testing.

The last submitted patch, 2618040.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 14: 2618040.patch, failed testing.

alexpott’s picture

Issue tags: +D8MI
plach’s picture

Issue tags: +language-base

I'll have a look to this ASAP...

plach’s picture

Assigned: Unassigned » plach
Issue tags: +sprint

On this

plach’s picture

Assigned: plach » Unassigned

The last submitted patch, 22: language-type_reset-2618040-22.test.patch, failed testing.

plach’s picture

Component: language system » language.module
Berdir’s picture

I can't say I fully understand that language configuration/purging stuff but the fix seems to make sense, the test looks good and fails as expected.

Let's get back to 0 criticals :)

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

That's what I wanted to do...

The last submitted patch, 22: language-type_reset-2618040-22.test.patch, failed testing.

catch’s picture

#22 looks right to me.

catch’s picture

Fixable on commit:

+++ b/core/modules/system/src/Tests/Module/ConfigLangTypeTest.php
@@ -0,0 +1,69 @@
+   * Tests alteration config of configurable language types.

alteration of

or just altering.

plach’s picture

@Berdir:

I can't say I fully understand that language configuration/purging stuff

You are not the only one: #2166879: Clean-up code managing language type configurability ;)

This is a clear case where a straight conversion from D7 was not the right move. Or at least we got it wrong :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think the test should be a part of LanguageNegotiationInfoTest

plach’s picture

The last submitted patch, 34: language-type_reset-2618040-34.test.patch, failed testing.

plach’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: language-type_reset-2618040-22.test.patch, failed testing.

The last submitted patch, 34: language-type_reset-2618040-34.test.patch, failed testing.

cilefen’s picture

Status: Needs work » Reviewed & tested by the community

I think this was supposed to stay RTBC

The last submitted patch, 34: language-type_reset-2618040-34.test.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: language-type_reset-2618040-22.test.patch, failed testing.

cilefen’s picture

Not sure how to please the bot/issue integration.

YesCT’s picture

(@cilefen maybe related to #2598438: Improve logic and/or UI around retesting patches in RTBC issues. hiding previous patches)

was reviewing the interdiff in #34 and it moves the test fine. rtbc++ for that.

but while I was at it, I fixed the nit in #31 and another nit.

I'm not sure if the following questions are enough to block this...
I also read the entire patch, and

  1. +++ b/core/modules/language/language.module
    @@ -311,8 +311,13 @@ function language_negotiation_url_domains() {
    +    // Since newly (un)installed modules may change the default settings for
    

    this comment makes it seem like uninstalling could also cause the problem.

    do we need a change in the hook for uninstalling modules? ah, no. because the uninstall hook is a wrapper for the install hook.

    function language_modules_uninstalled($modules) {
      language_modules_installed($modules);
    }
  2. +++ b/core/modules/language/language.module
    @@ -311,8 +311,13 @@ function language_negotiation_url_domains() {
    -    $negotiator->updateConfiguration(array());
    +    $configurable = \Drupal::config('language.types')->get('configurable');
    +    $negotiator->updateConfiguration($configurable);
    

    why do we do this here instead of a change in updateConfiguration()

  3. +++ b/core/modules/language/src/Tests/LanguageNegotiationInfoTest.php
    @@ -174,4 +174,37 @@ protected function checkFixedLanguageTypes() {
    +    // After installing another module, the config should be the same.
    +    $this->drupalPostForm('admin/modules', ['modules[Core][field][enable]' => 1], t('Install'));
    +    $this->assertTrue($this->isLanguageTypeConfigurable($test_type), 'Language type is still configurable.');
    

    this test uses the field module. but what is it about the field module that makes this test fail. is it that it does not try and make the language configurable?

    I'm wondering if we should have a test module we use that has exactly the conditions we need instead of re-using field.

    Also, I wonder if, as the comment in the fix states, uninstalling a module could have cause the same problem, if we should include that in the test also.

The last submitted patch, 43: language-type_reset-2618040-37-testsonly.patch, failed testing.

catch’s picture

Status: Reviewed & tested by the community » Needs work

why do we do this here instead of a change in updateConfiguration()

I think we should look at that in a follow-up, my original patch was hoping that would work already (clearly it doesn't), but it'd also be a behaviour change so something we should change in 8.1.x.

Let's add the test coverage for uninstalling a module though - that's the sort of thing that could easily get missed if this code gets refactored later.

Maouna’s picture

Assigned: Unassigned » Maouna
YesCT’s picture

Issue summary: View changes

added note to the issue summary to
add these people from the older duplicate issue #2281211: Content language detection settings gets reverted to default to the commit message (for opening the issue, and steps to reproduce):
steelsector, matsbla, SiliconMind, vodde83
(I know we can't at this time add them to the database, but we can to the commit message)

@catch just to clarify, are we ok with using the field module in the test vs another test module? Or is that followup material also?

opened the followup @catch asked for in #45. it is postponed on this issue. #2623788: updateConfiguration() should be able to override configurable of language types when modules are installed or uninstalled it probably needs a better title and an update to the issue summary.

catch’s picture

@YesCT I think it's probably fine to use field module in the test. It shouldn't matter which module is enabled in the test - just that any module gets enabled. However a comment explaining that would be good.

Maouna’s picture

this test uses the field module. but what is it about the field module that makes this test fail. is it that it does not try and make the language configurable?

No, it is not about the field module. There is no particular reason why I chose that.

I'm wondering if we should have a test module we use that has exactly the conditions we need instead of re-using field

Ok, I added the test_module, which only contains the info.yml. Already with that the test fails.

Let's add the test coverage for uninstalling a module though - that's the sort of thing that could easily get missed if this code gets refactored later.

I added that in the new patch, too.

Maouna’s picture

Assigned: Maouna » Unassigned
Status: Needs work » Needs review

Sorry, did not realized you commented already. So, we stick with #37 or #49?

catch’s picture

New module is fine too, just didn't want to block on it.

The last submitted patch, 43: language-type_reset-2618040-37-testsonly.patch, failed testing.

The last submitted patch, 49: language-type_reset-2618040-47-testsonly.patch, failed testing.

plach’s picture

Status: Needs review » Reviewed & tested by the community

why do we do this here instead of a change in updateConfiguration()

I think we should look at that in a follow-up, my original patch was hoping that would work already (clearly it doesn't), but it'd also be a behaviour change so something we should change in 8.1.x.

That would be an API change. The PHP docs clearly state the argument should be an array of configurable language type names, so the previous code was plain wrong and the current one should be correct.
Or are you suggesting to make the parameter optional and default to that code?

The interdiff looks good to me.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Yes was thinking optional parameter - but would be 8.1.x change.

Interdiff looks good to me too, so ommitted/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

  • catch committed 043fb23 on 8.1.x
    Issue #2618040 by Maouna, plach, catch, YesCT, steelsector, matsbla,...

  • catch committed 5754b49 on
    Issue #2618040 by Maouna, plach, catch, YesCT, steelsector, matsbla,...

The last submitted patch, 43: language-type_reset-2618040-37-testsonly.patch, failed testing.

The last submitted patch, 43: language-type_reset-2618040-37.patch, failed testing.

The last submitted patch, 49: language-type_reset-2618040-47-testsonly.patch, failed testing.

Status: Fixed » Needs work

The last submitted patch, 49: language-type_reset-2618040-47.patch, failed testing.

catch’s picture

Status: Needs work » Fixed
plach’s picture

Maouna’s picture

Thank you very much for all your work!

Gábor Hojtsy’s picture

Issue tags: -sprint

Status: Fixed » Closed (fixed)

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