I encounter an error when I want to add a new language in the Drupal site using /admin/config/regional/language/add path.
The error is:
'Error: Call to a member function set Weight() on null in Drupal\language\Configurable LanguageManager->updateLockedLanguageWeights()'

Even if the error is received the language is created when I go on the language list.

I am using Drupal 8.5.1 version.

Steps to reproduce:

1. Install Drupal 11.1 with the default English language
2. Go to admin/config/regional/language/add, select any language, e.g. Finnish.
3. CLick Save.
4. Get error Call to a member function setWeight() on null in Drupal\language\ConfigurableLanguageManager->updateLockedLanguageWeights() (line 357 of core/modules/language/src/ConfigurableLanguageManager.php).
5. Go back to the list of languages admin/config/regional/language and see that the Finnish is added.
6. Edit the language and save -> get the same error.

Issue fork drupal-3002532

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

iuana created an issue. See original summary.

Omirr85’s picture

Getting the same error on Drupal 8.6.2 when adding a new language (Dutch) through the configuration menu.

The website encountered an unexpected error. Please try again later.
Error: Call to a member function setWeight() on null in Drupal\language\ConfigurableLanguageManager->updateLockedLanguageWeights() (line 357 of core/modules/language/src/ConfigurableLanguageManager.php).
Drupal\language\ConfigurableLanguageManager->updateLockedLanguageWeights() (Line: 133)
Drupal\language\Entity\ConfigurableLanguage->postSave(Object, ) (Line: 506)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, ) (Line: 432)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 263)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 390)
Drupal\Core\Entity\Entity->save() (Line: 632)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 296)
Drupal\Core\Entity\EntityForm->save(Array, Object) (Line: 87)
Drupal\language\Form\LanguageAddForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('language_admin_add_form', Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder->buildForm('language_admin_add_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 665)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Afterwards, the lagnuage is imported with 0 translations. If I would try to set the new language as default, it get a similar error and errors at the top of every configuration page until I set the default to English again.

Omirr85’s picture

I have the same error after adding a new language (Dutch) in the configuration menu's

The website encountered an unexpected error. Please try again later.
Error: Call to a member function setWeight() on null in Drupal\language\ConfigurableLanguageManager->updateLockedLanguageWeights() (line 357 of core/modules/language/src/ConfigurableLanguageManager.php).
Drupal\language\ConfigurableLanguageManager->updateLockedLanguageWeights() (Line: 133)
Drupal\language\Entity\ConfigurableLanguage->postSave(Object, ) (Line: 506)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, ) (Line: 432)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 263)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 390)
Drupal\Core\Entity\Entity->save() (Line: 632)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 296)
Drupal\Core\Entity\EntityForm->save(Array, Object) (Line: 87)
Drupal\language\Form\LanguageAddForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('language_admin_add_form', Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder->buildForm('language_admin_add_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 665)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

After this, the language is imported with 0 translations.
When I set this as default language, it gives more errors on every configuration page until I set English as the default again.

Power2All’s picture

I got the same issue.
Upgraded the core and such, same issue as with adding Dutch.
Seems like a bug in the latest Drupal ?

rajeevchoudhary’s picture

StatusFileSize
new69.12 KB

Hi Guys,

I have tested the Dutch language installation on Drupal 8 and set this as default language, it works fine.

Can you elaborate little bit more, so I understand more.

Power2All’s picture

StatusFileSize
new33.81 KB
new14.75 KB
new65.65 KB

Made some screenshots, which shows the error and what I exactly do:

Image 1

Image 2

Image 3

rajeevchoudhary’s picture

Hi Power2All,

I have tested same with Drupal Version 8.5.1. Its working fine.

You may review here.

https://dmydh.ply.st/

UserName: admin
Password :admin

walii’s picture

Hi,

I have tested the same with Dutch and Hindi language on Drupal 8.5.5 and set this as both one by one as default language, it works fine.
please update your core

Omirr85’s picture

An updated core did indeed fix this. Thanks to however fixed the core ;-)

rajeevchoudhary’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

bezlash@gmail.com’s picture

Hi,

I'm experiencing this same issue on 8.6.10. Does anyone know what the fix for this was?

Thanks

sanjayk’s picture

I am also facing same issue but when i am trying to add custom language i.e. en-bg

dan2k3k4’s picture

Version: 8.5.x-dev » 8.7.x-dev
StatusFileSize
new832 bytes

I came across this issue on Drupal 8.7.8, so providing a patch but I'm not able to change the status from Closed to Needs Review...

lendude’s picture

Status: Closed (fixed) » Needs review
Issue tags: +Needs steps to reproduce, +Needs tests

Opening this back up, since it should not have been marked 'Fixed' to begin with, it probably should have been marked 'Outdated' or 'Cannot reproduce' if anything.

We still need steps to reproduce this and an automated test to prove that this is a bug and a solution like #14 isn't just hiding broken config.

dan2k3k4’s picture

For my "steps to reproduce" - it seems to be that using the current Amazeelabs/silverback "composer" dependency and then running silverback setup, then head to the Languages page to add a new language, then add a language and you'll get the error.

Steps to reproduce:

  1. Run the command:

    composer create-project drupal-composer/drupal-project:8.x-dev my-project --no-interaction

  2. Add silverback with the following:
    cd my-project
    composer require amazeelabs/silverback
    ./vendor/bin/silverback init
    composer install
    yarn
  3. Go to the languages page, you should see no languages listed on the page
  4. Add new language, such as French
  5. Save and you should get the error

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

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

vuil’s picture

The patch of #14 works for us. (D8.5.15)

vuil’s picture

StatusFileSize
new815 bytes

Add the patch for Drupal 8.7.x core version.

vuil’s picture

StatusFileSize
new815 bytes

Add the patch for Drupal 8.8.x core version.

dropa’s picture

Getting this error with zxx and und language codes, but not entirely sure why, since this does not seem to appear always. Given that, it could be that patch for this could be somewhat harmful and instead the configuration needs to be fixed.

dropa’s picture

In my case it seems that this error appeared when I tried to run drush si --existing-config -y and the configuration was missing configuration that should have been delivered by language module. Could you confirm whether that is the case for you as well?

vuil’s picture

Hide the old patch.

binnythomas’s picture

I am receiving the same error on core version 8.8.5. The language is added however without any issues.

binnythomas’s picture

I can confirm that patch #20 is working for me. Core version 8.8.5

vuil’s picture

Version: 8.8.x-dev » 8.9.x-dev
quietone’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Needs review » Needs work

Ran into this on 9.1.x while trying to save the demo_umami profile config, 'language.entity.es'. This was while developing a Kernel migration test for the json_api source plugin.

    $entity_type_manager->getStorage('configurable_language')
      ->create($source->read('language.entity.es'))
      ->save();

Since that fails, just creating the language works.

    $entity_type_manager->getStorage('configurable_language')
      ->create([
        'id' => 'es',
      ])->save();

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

bob.hinrichs’s picture

Error persists on Drupal 9.1, when submitting admin form to enable Spanish.
This is a site that was set up from configuration. The patch #20 works for me.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

oknate’s picture

Error persists on 9.2.6. I was experiencing it on /admin/config/regional/language after adding Arabic to the site. Patch #20 worked. It removes the fatal error.

beram’s picture

Just came across the same issue when writing a kernel test.

For #3002532-21: Call to a member function set Weight() on null in Drupal\language\Configurable LanguageManager->updateLockedLanguageWeights()/#3002532-22: Call to a member function set Weight() on null in Drupal\language\Configurable LanguageManager->updateLockedLanguageWeights() and #3002532-27: Call to a member function set Weight() on null in Drupal\language\Configurable LanguageManager->updateLockedLanguageWeights(), it seems the issue is that non-locked languages do not depend on locked languages.
So we cannot guarantee that locked languages exists just by installing the config since the dependency is not set.
Does the dependency should be clearly defined for each config? If yes, then we should also make sure to add the dependencies when generating the config in addition of the current patch no?

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

will kirchheimer’s picture

Seeing this issue on a 9.4.7

[error] Call to a member function setWeight() on null

This appears both when I am using the UI and when attempting to add programmatically like:

In code:

  ConfigurableLanguage::create(['id' => 'zer', 'label' => 'zero', 'weight' => -1])->save();

And in drush:

 drush ev "\Drupal\language\Entity\ConfigurableLanguage::create(['id' => 'one', 'label' => 'drushtest'])->save();"

 drush ev "\Drupal\language\Entity\ConfigurableLanguage::create(['id' => 'two', 'label' => 'drushtest2', 'weight' => '1'])->save();"

This also happens when I use the UI to delete a custom language, returning this error:

The website encountered an unexpected error. Please try again later.
Error: Call to a member function setWeight() on null in Drupal\language\ConfigurableLanguageManager->updateLockedLanguageWeights() (line 369 of core/modules/language/src/ConfigurableLanguageManager.php).

Patch 20 worked for me.

MabelYu’s picture

I have the same question too. and patch#20 worked for me too

in the file :core/modules/language/src/ConfigurableLanguageManager.php

change the origin updateLockedLanguageWeights function

// public function updateLockedLanguageWeights() {
  //   // Get the weight of the last configurable language.
  //   $configurable_languages = $this->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
  //   $max_weight = end($configurable_languages)->getWeight();

  //   $locked_languages = $this->getLanguages(LanguageInterface::STATE_LOCKED);
  //   // Update locked language weights to maintain the existing order, if
  //   // necessary.
  //   if (reset($locked_languages)->getWeight() <= $max_weight) {
  //     foreach ($locked_languages as $language) {
  //       // Update system languages weight.
  //       $max_weight++;
  //       ConfigurableLanguage::load($language->getId())
  //         ->setWeight($max_weight)
  //         ->save();
  //     }
  //   }
  // }

into this function:

public function updateLockedLanguageWeights() {
  foreach ($locked_languages as $language) {
    // Update system languages weight.
    $max_weight++;
      $configurable_language = ConfigurableLanguage::load($language->getId());
      if ($configurable_language) {
        $configurable_language->setWeight($max_weight)->save();
      }
  }
}

Munavijayalakshmi made their first commit to this issue’s fork.

pradhumanjain2311’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB
new1.3 KB

Addressed Comment #37. Needs Review.

pooja saraah’s picture

StatusFileSize
new1.4 KB
new794 bytes

Fixed failed commands on #39
Attached patch against Drupal 10.1.x

anchal_gupta’s picture

StatusFileSize
new1.47 KB
new743 bytes

I have fix CS error. Please review it

ankit agrawal’s picture

#39 worked for me on 9.5.
Thanks

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs work

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

#41 has some erros
And this was previously tagged for steps to reproduce and tests which still need to happen.

Thanks.

prem suthar’s picture

StatusFileSize
new1.48 KB

Try TO Fix the #41 custom CMD Failed Patch.

vuil’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gantal made their first commit to this issue’s fork.

gantal’s picture

Issue tags: -

The last 3 patches did not work for me on Drupal 10.1, unfortunately. I created a merge request adding simple validation before setting weights, which I belatedly realized is the same as the patch in #20.

The larger issue seems to be that locked languages (and the default language in my case) cannot be loaded as ConfigurableLanguage entities.

naveentinu90’s picture

StatusFileSize
new815 bytes

Since the last patches did not work for me on Drupal 10.1.x.
Thus I have created a new patch and its is working fine.

Kindly review the patch.

sokru’s picture

I've a patch from this issue on few projects, however I believe the root cause is same as @Dropa mentioned on #21 & #22. Tried to reproduce the issue with steps from #36, but no luck. So I'd vote for closing this as outdated/cannot reproduce (on clean install). The missing configuration should be rather easy to find with https://www.drupal.org/project/config_inspector now that #3426309: Add config validation for weights (blocks, filters, etc. all use weights) has landed on 10.3.x

tolstoydotcom’s picture

StatusFileSize
new2.74 KB

I had this issue on Drupal 11.0.4 and it was because there was no language.entity.en config entity. There were such entities for various other languages, just not en. I have no idea how that happened.

Just because it might mask an underlying issue is no reason not to make the updateLockedLanguageWeights method more bulletproof.

I've attached my attempt to do that based on D11 dev of Oct 18, 2024.

oknate’s picture

I ran into this today. It couldn't load 'und' and 'xxx' in Drupal 10.

I think we shouldn't increment if we can't load the language:

foreach ($locked_languages as $language) {
        $configurable_language = ConfigurableLanguage::load($language->getId());
        if (!$configurable_language instanceof ConfigurableLanguage) {
          continue;
        }
        // Update system languages weight.
        $max_weight++;
        $configurable_language
          ->setWeight($max_weight)
          ->save();
      }

oknate’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Tags for steps to reproduce, issue summary update, and test still applyl

yevko’s picture

yevko’s picture

Updated the issue summary with Steps to reproduced.

Also tested the MR !10640 - and confirm it works

mikemadison’s picture

I hit this issue testing Drupal CMS. Patching with #56 resolved the problem for me. Adding the Drupal CMS dependency tag on this issue since it seems to block the ability to install new languages in Drupal CMS.

nicolas s.’s picture

Patch #56 works for D11.1.2

macsim’s picture

Patch #56 works on D11.1.3

oknate’s picture

Patch #56 works on 10.4.2

phenaproxima’s picture

Issue tags: +Recipes initiative

This bug can prevent recipes from shipping translations without adding the following workaround to language entities:

dependencies:
  config:
    - language.entity.und
    - language.entity.zxx

Tagging, therefore, as part of the Recipes Initiative.

phenaproxima’s picture

Question about the proposed fix here:

  • Why is there a need to return the number of languages changed? That seems superfluous and is adding complexity to the patch.
  • Could we not just fix this by using the null-safe operator when trying to load the configurable language that may or may not exist? Surely that would get us past this problem elegantly, and would fix the flawed assumption which is causing the bug (namely, that the Language module is assuming that all of its config actually exists, which is not and never has been a safe assumption).
tolstoydotcom’s picture

It isn't really necessary to return the number of rows processed but it's only using three lines. I can take those out if that causes problems. Or I can add a return type hint.

The original method is making several assumptions that might result in errors, I tried to resolve those. There are such assumptions before the ConfigurableLanguage::load line so I don't think just fixing that is going to solve it. I'm open to trying to make it even more bulletproof, such as by checking that things are arrays.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

aimevp’s picture

I had the fatal error on a project with Drupal 11.4.4. I installed the changes from the latest MR update and the error was gone.

rajab natshah’s picture

I faced the same issue