diff --git a/core/core.services.yml b/core/core.services.yml index 7d9e831..39a6d6b 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -100,7 +100,7 @@ services: class: Drupal\Core\Config\InstallStorage config.typed: class: Drupal\Core\Config\TypedConfigManager - arguments: ['@config.storage', '@config.storage.schema'] + arguments: ['@config.storage', '@config.storage.schema', '@module_handler'] database: class: Drupal\Core\Database\Connection factory_class: Drupal\Core\Database\Database diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index 71aa0bc..96ecf66 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -12,6 +12,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\String; use Drupal\Core\Config\TypedConfigManagerInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; /** * Manages config type plugins. @@ -40,19 +41,49 @@ class TypedConfigManager extends PluginManagerBase implements TypedConfigManager protected $definitions; /** + * The module handler to invoke the alter hook. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * Name of the alter hook if one should be invoked. + * + * @var string + */ + protected $alterHook; + + /** * Creates a new typed configuration manager. * * @param \Drupal\Core\Config\StorageInterface $configStorage * The storage controller object to use for reading schema data * @param \Drupal\Core\Config\StorageInterface $schemaStorage * The storage controller object to use for reading schema data + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler */ - public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage) { + public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, ModuleHandlerInterface $module_handler) { + $this->alterInfo($module_handler, 'config_type_info'); $this->configStorage = $configStorage; $this->schemaStorage = $schemaStorage; } /** + * Initializes the alter hook. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke the alter hook with. + * @param string $alter_hook + * Name of the alter hook. + */ + protected function alterInfo(ModuleHandlerInterface $module_handler, $alter_hook) { + $this->moduleHandler = $module_handler; + $this->alterHook = $alter_hook; + } + + /** * Gets typed configuration data. * * @param string $name @@ -161,14 +192,18 @@ public function getDefinition($base_plugin_id) { */ public function getDefinitions() { if (!isset($this->definitions)) { - $this->definitions = array(); + $definitions = array(); foreach ($this->schemaStorage->listAll() as $name) { if ($schema = $this->schemaStorage->read($name)) { foreach ($schema as $type => $definition) { - $this->definitions[$type] = $definition; + $definitions[$type] = $definition; } } } + if ($this->alterHook) { + $this->moduleHandler->alter($this->alterHook, $definitions); + } + $this->definitions = $definitions; } return $this->definitions; } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php index 3b406b1..ba6452e 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php @@ -242,4 +242,13 @@ function testSchemaData() { $this->assertEqual($site_slogan->getValue(), $new_slogan, 'Successfully updated the contained configuration data'); } + + /** + * Tests the alter hook for TypedConfig data types. + */ + function testSchemaTypeAlter() { + $definitions = config_typed()->getDefinitions(); + $this->assertTrue($definitions['label']['alter_hook_invoked']); + } + } diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index b815610..0674f79 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -86,3 +86,10 @@ function config_test_entity_info_alter(&$entity_info) { unset($entity_info['config_test_no_status']['entity_keys']['status']); $entity_info['config_test_no_status']['config_prefix'] = 'config_test.no_status'; } + +/** + * Implements hook_config_type_info_alter(). + */ +function config_test_config_type_info_alter(&$info) { + $info['label']['alter_hook_invoked'] = TRUE; +} diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php index 9937d78..194934b 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigManager.php @@ -10,6 +10,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Config\StorageInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; /** * Manages localized configuration type plugins. @@ -42,15 +43,17 @@ class LocaleConfigManager extends TypedConfigManager { * The storage controller object to use for reading configuration data. * @param \Drupal\Core\Config\StorageInterface $schemaStorage * The storage controller object to use for reading schema data. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler * @param \Drupal\Core\Config\StorageInterface $installStorage * The storage controller object to use for reading default configuration * data. * @param \Drupal\locale\StringStorageInterface $localeStorage * The locale storage to use for reading string translations. */ - public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, StorageInterface $installStorage, StringStorageInterface $localeStorage) { + public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, ModuleHandlerInterface $module_handler, StorageInterface $installStorage, StringStorageInterface $localeStorage) { // Note we use the install storage for the parent constructor. - parent::__construct($configStorage, $schemaStorage); + parent::__construct($configStorage, $schemaStorage, $module_handler); $this->installStorage = $installStorage; $this->localeStorage = $localeStorage; } diff --git a/core/modules/locale/locale.services.yml b/core/modules/locale/locale.services.yml index f632704..0f7ee37 100644 --- a/core/modules/locale/locale.services.yml +++ b/core/modules/locale/locale.services.yml @@ -6,7 +6,7 @@ services: arguments: ['@language_manager', '@config.context'] locale.config.typed: class: Drupal\locale\LocaleConfigManager - arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage'] + arguments: ['@config.storage', '@config.storage.schema', '@module_handler', '@config.storage.installer', '@locale.storage'] locale.storage: class: Drupal\locale\StringDatabaseStorage arguments: ['@database'] diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 0bde16e..6c93356 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -144,6 +144,16 @@ function hook_data_type_info_alter(&$data_types) { } /** + * Alter available data types for typed config. + * + * @param array $data_types + * An array of data type information. + */ +function hook_config_type_info_alter(&$data_types) { + $data_types['label']['form_element_class'] = '\Drupal\mymodule\TypedConfig\Label'; +} + +/** * Declare queues holding items that need to be run periodically. * * While there can be only one hook_cron() process running at the same time,