Resolve #2845437 "Process translation config"
Closes #2845437
Merge request reports
Activity
added 162 commits
-
ce72390d...33630ea5 - 161 commits from branch
project:11.x
- 9eb429a3 - Initial commit made from the latest patch
-
ce72390d...33630ea5 - 161 commits from branch
added 2 commits
added 624 commits
-
d59ac7b5...5397521d - 623 commits from branch
project:11.x
- abf68a1b - Initial commit made from the latest patch
-
d59ac7b5...5397521d - 623 commits from branch
added 289 commits
-
abf68a1b...ca4e4a81 - 288 commits from branch
project:11.x
- 26ccdeb8 - Initial commit made from the latest patch
-
abf68a1b...ca4e4a81 - 288 commits from branch
added 15 commits
-
26ccdeb8...81ff548f - 14 commits from branch
project:11.x
- d83e746e - Initial commit made from the latest patch
-
26ccdeb8...81ff548f - 14 commits from branch
added 17 commits
-
d83e746e...6fc1e6f2 - 16 commits from branch
project:11.x
- 1400b9e1 - Initial commit made from the latest patch
-
d83e746e...6fc1e6f2 - 16 commits from branch
added 116 commits
-
1400b9e1...89278799 - 115 commits from branch
project:11.x
- 9f92d18c - Initial commit made from the latest patch
-
1400b9e1...89278799 - 115 commits from branch
160 160 $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY; 161 $collection_info = $this->configManager->getConfigCollectionInfo(); 161 162 if (is_dir($optional_install_path)) { 162 163 // Install any optional config the module provides. 163 164 $storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION); 164 $this->installOptionalConfig($storage, ''); 165 foreach ($collection_info->getCollectionNames() as $collection) { 166 $this->installOptionalConfig($storage, '', $collection); 167 } 165 168 } 166 169 // Install any optional configuration entities whose dependencies can now 167 170 // be met. This searches all the installed modules config/optional 168 171 // directories. 169 172 $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE, $this->installProfile); 170 $this->installOptionalConfig($storage, [$type => $name]); 173 $dependency = $name == 'update' ? [] : [$type => $name]; changed this line in version 11 of the diff
211 221 212 222 // Filter the list of configuration to only include configuration that 213 223 // should be created. 214 $list = array_filter($list, function ($config_name) use ($existing_config) { 224 $list = array_filter($list, function ($config_name) use ($existing_config, $collection) { 225 if ($collection != StorageInterface::DEFAULT_COLLECTION) { 226 return TRUE; 227 } - Comment on lines +225 to +227
Thanks for the catch! I've updated logic and added comments above new lines of code. I've decided to keep this change, but add code for the part, where missing dependencies are checked. For configurations from non-default collection I replace $data with data from configuration, loaded from default collection, since it always has full data, while non-default collection's configuration usually contains only translations.
I've also updated test - added configuration with missing dependency and assertion, that it has empty data after module's configuration is installed.
added 197 commits
-
9f92d18c...c17cc49d - 196 commits from branch
project:11.x
- 641c4bb5 - Initial commit made from the latest patch
-
9f92d18c...c17cc49d - 196 commits from branch
added 90 commits
-
641c4bb5...b21bcf4e - 89 commits from branch
project:11.x
- 59670134 - Process translation config files for custom modules
-
641c4bb5...b21bcf4e - 89 commits from branch
added 1 commit
- ef7015ed - Process translation config files for custom modules
158 158 $profile_installed = in_array($this->drupalGetProfile(), $this->getEnabledExtensions(), TRUE); 159 159 if (!$this->isSyncing() && (!InstallerKernel::installationAttempted() || $profile_installed)) { 160 160 $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY; 161 $collection_info = $this->configManager->getConfigCollectionInfo(); 161 162 if (is_dir($optional_install_path)) { 162 163 // Install any optional config the module provides. 163 164 $storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION); 164 $this->installOptionalConfig($storage, ''); 165 foreach ($collection_info->getCollectionNames() as $collection) { 166 $this->installOptionalConfig($storage, '', $collection); Ugh - the second param here is type-hinted as an array, so this is jarring to see a string passed. Can we get a follow-up issue created to fix that as it's out of scope here.
I think we should use a named argument here, i.e.
$this->installOptionalConfig($storage, collection: $collection)
That way we fix at least one instance of passing a string when an array is expected (there are others though, hence the follow-up)
177 182 /** 178 183 * {@inheritdoc} 179 184 */ 180 public function installOptionalConfig(?StorageInterface $storage = NULL, $dependency = []) { 185 public function installOptionalConfig(?StorageInterface $storage = NULL, $dependency = [], $collection = StorageInterface::DEFAULT_COLLECTION) { 177 182 /** 178 183 * {@inheritdoc} 179 184 */ 180 public function installOptionalConfig(?StorageInterface $storage = NULL, $dependency = []) { 185 public function installOptionalConfig(?StorageInterface $storage = NULL, $dependency = [], $collection = StorageInterface::DEFAULT_COLLECTION) { 181 186 $profile = $this->drupalGetProfile(); 182 187 $enabled_extensions = $this->getEnabledExtensions(); 183 188 $existing_config = $this->getActiveStorages()->listAll(); 184 189 190 // Get proper storage for non-default collection. 191 if (!empty($storage) && $storage->getCollectionName() != $collection) { 192 $default_storage = $storage; 193 $storage = $storage->createCollection($collection); 238 253 } 239 254 240 255 foreach ($config_to_create as $config_name => $data) { 256 // For non-default collection's config load data from default one 257 // to get proper dependencies. 258 if (!empty($default_storage) && $collection != StorageInterface::DEFAULT_COLLECTION) { 57 'locales_source', 58 'locales_target', 59 'locales_location', 60 ]; 61 $this->installSchema('locale', $locale_tables); 62 \Drupal::service('theme_installer')->install(['stark']); 63 $language = ConfigurableLanguage::createFromLangcode('fr'); 64 $language->save(); 65 \Drupal::service('module_installer')->install(['config_install_optional_test']); 66 $this->installConfig(['config_install_optional_test']); 67 // Check, if block 'test_translate' has proper translation. 68 $config_translation = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'block.block.test_translate'); 69 $this->assertTrue($config_translation->get('settings.label') == 'Title (fr)'); 70 // Check, if block with missing dependency has empty config. 71 $config_translation = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'block.block.test_translate_unmet'); 72 $this->assertTrue(empty($config_translation->getRawData())); 630 630 protected function filterOverride(array $override_data, array $translatable) { 631 631 $filtered_data = []; 632 632 foreach ($override_data as $key => $value) { 633 if (isset($translatable[$key])) { 633 if (isset($translatable[$key]) && is_array($value)) { 634 634 // If the translatable default configuration has this key, look further 635 // for subkeys or ignore this element for scalar values. 636 if (is_array($value)) { 637 $value = $this->filterOverride($value, $translatable[$key]); 638 if (!empty($value)) { 639 $filtered_data[$key] = $value; 640 } 635 // for subkeys. 636 $value = $this->filterOverride($value, $translatable[$key]); 637 if (!empty($value)) { the use of empty here (Although existing) feels like a bug waiting to happen https://3v4l.org/VINWv
added 1 commit
- 373d758a - 2845437: Add strict comparision for conditioning statement.