Problem/Motivation
When installing the site via drush si --existing-config -y
it throws the following error:
Error: Call to a member function setWeight() on null in /app/webroot/core/modules/language/src/ConfigurableLanguageManager.php on line 357 #0 /app/webroot/core/modules/language/src/Entity/ConfigurableLanguage.php(140): Drupal\language\ConfigurableLanguageManager->updateLockedLanguageWeights()
#1 /app/webroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(525): Drupal\language\Entity\ConfigurableLanguage->postSave(Object(Drupal\Core\Config\Entity\ConfigEntityStorage), true)
#2 /app/webroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(451): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\language\Entity\ConfigurableLanguage), true)
#3 /app/webroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(263): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\language\Entity\ConfigurableLanguage))
#4 /app/webroot/core/lib/Drupal/Core/Entity/EntityBase.php(394): Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object(Drupal\language\Entity\ConfigurableLanguage))
#5 /app/webroot/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(613): Drupal\Core\Entity\EntityBase->save()
#6 /app/webroot/core/includes/install.core.inc(1688): Drupal\Core\Config\Entity\ConfigEntityBase->save()
#7 /app/webroot/core/includes/install.core.inc(1733): install_download_additional_translations_operations(Array)
#8 /app/webroot/core/includes/install.core.inc(631): install_import_translations(Array)
#9 /app/webroot/core/includes/install.core.inc(577): install_run_task(Array, Array)
#10 /app/webroot/core/includes/install.core.inc(118): install_run_tasks(Array, NULL)
#11 /app/vendor/drush/drush/includes/drush.inc(238): install_drupal(Object(Composer\Autoload\ClassLoader), Array)
#12 /app/vendor/drush/drush/includes/drush.inc(223): drush_call_user_func_array('install_drupal', Array)
#13 /app/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php(141): drush_op('install_drupal', Object(Composer\Autoload\ClassLoader), Array)
#14 [internal function]: Drush\Commands\core\SiteInstallCommands->install('minimal', Array)
#15 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#16 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#17 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(178): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#18 /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(302): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#19 /app/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /app/vendor/symfony/console/Application.php(971): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /app/vendor/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /app/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /app/vendor/drush/drush/src/Runtime/Runtime.php(112): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /app/vendor/drush/drush/src/Runtime/Runtime.php(41): Drush\Runtime\Runtime->doRun(Array)
#25 /app/vendor/drush/drush/drush.php(66): Drush\Runtime\Runtime->run(Array)
#26 /app/vendor/drush/drush/includes/preflight.inc(17): require('/app/vendor/dru...')
#27 phar:///usr/local/bin/drush/bin/drush.php(141): drush_main()
#28 /usr/local/bin/drush(10): require('phar:///usr/loc...')
#29 {main}
Error: Call to a member function setWeight() on null in Drupal\language\ConfigurableLanguageManager->updateLockedLanguageWeights() (line 357 of /app/webroot/core/modules/language/src/ConfigurableLanguageManager.php).
Proposed resolution
There is a ConfigurableLanguage::load in the function throwing the error, I think the language is not in the DB yet because site is being installed, I propose to add a condition to check if the language was loaded.