diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index cab8816..f2f9d74 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -477,10 +477,15 @@ public function hasTranslation($name, $langcode) { * configuration exists. */ public function getDefaultConfigLangcode($name) { - $shipped = $this->defaultConfigStorage->read($name); - if (!empty($shipped)) { - return !empty($shipped['langcode']) ? $shipped['langcode'] : 'en'; + // Config entities that do not have the 'default_config_hash' cannot be + // shipped configuration regardless of whether there is a name match. + if (!\Drupal::service('config.manager')->getEntityTypeIdByName($name) || !empty($this->configFactory->get($name)->get('default_config_hash'))) { + $shipped = $this->defaultConfigStorage->read($name); + if (!empty($shipped)) { + return !empty($shipped['langcode']) ? $shipped['langcode'] : 'en'; + } } + return NULL; } /** diff --git a/core/modules/locale/src/Tests/LocaleConfigManagerTest.php b/core/modules/locale/src/Tests/LocaleConfigManagerTest.php index 39f14cb..93cfb7f 100644 --- a/core/modules/locale/src/Tests/LocaleConfigManagerTest.php +++ b/core/modules/locale/src/Tests/LocaleConfigManagerTest.php @@ -7,6 +7,7 @@ namespace Drupal\locale\Tests; +use Drupal\block\Entity\Block; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\simpletest\KernelTestBase; @@ -22,7 +23,7 @@ class LocaleConfigManagerTest extends KernelTestBase { * * @var array */ - public static $modules = array('language', 'locale', 'locale_test'); + public static $modules = array('system', 'language', 'locale', 'locale_test', 'block'); /** * Tests hasTranslation(). @@ -72,6 +73,37 @@ public function testGetDefaultConfigLangcode() { $this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode('locale_test_translate.settings'), 'Before installing a module the locale config manager can not access the shipped configuration.'); \Drupal::service('module_installer')->install(['locale_test_translate']); $this->assertEqual('en', \Drupal::service('locale.config_manager')->getDefaultConfigLangcode('locale_test_translate.settings'), 'After installing a module the locale config manager can get the shipped configuration langcode.'); + + $block = Block::create(array( + 'id' => 'test_default_config', + 'theme' => 'classy', + 'status' => TRUE, + 'region' => 'content', + 'plugin' => 'local_tasks_block', + 'settings' => [ + 'id' => 'local_tasks_block', + 'label' => $this->randomMachineName(), + 'provider' => 'core', + 'label_display' => FALSE, + 'primary' => TRUE, + 'secondary' => TRUE, + ], + )); + $block->save(); + + // Install the theme after creating the block as installing the theme will + // install the block provided by the locale_test module. + \Drupal::service('theme_installer')->install(['classy']); + + // The test_default_config block provided by the locale_test module will not + // be installed because a block with the same ID already exists. + $this->installConfig(['locale_test']); + $this->assertEqual(NULL, \Drupal::service('locale.config_manager')->getDefaultConfigLangcode('block.block.test_default_config'), 'The block.block.test_default_config is not shipped configuration.'); + // Delete the block so we can install the one provided by the locale_test + // module. + $block->delete(); + $this->installConfig(['locale_test']); + $this->assertEqual('en', \Drupal::service('locale.config_manager')->getDefaultConfigLangcode('block.block.test_default_config'), 'The block.block.test_default_config is shipped configuration.'); } } diff --git a/core/modules/locale/tests/modules/locale_test/config/optional/block.block.test_default_config.yml b/core/modules/locale/tests/modules/locale_test/config/optional/block.block.test_default_config.yml new file mode 100644 index 0000000..15f0807 --- /dev/null +++ b/core/modules/locale/tests/modules/locale_test/config/optional/block.block.test_default_config.yml @@ -0,0 +1,19 @@ +langcode: en +status: true +dependencies: + theme: + - classy +id: test_default_config +theme: classy +region: content +weight: -40 +provider: null +plugin: local_tasks_block +settings: + id: local_tasks_block + label: Tabs + provider: core + label_display: '0' + primary: true + secondary: true +visibility: { }