diff --git a/core/core.services.yml b/core/core.services.yml index f30cee7..3b2fbac 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -116,7 +116,9 @@ services: class: Drupal\Core\Config\InstallStorage config.typed: class: Drupal\Core\Config\TypedConfigManager - arguments: ['@config.storage', '@config.storage.schema', '@cache.discovery'] + arguments: ['@config.storage', '@config.storage.schema', '@cache.discovery', '@module_handler'] + tags: + - { name: plugin_manager_cache_clear } context.handler: class: Drupal\Core\Plugin\Context\ContextHandler arguments: ['@typed_data_manager'] diff --git a/core/lib/Drupal/Core/Config/Schema/ConfigSchemaDiscovery.php b/core/lib/Drupal/Core/Config/Schema/ConfigSchemaDiscovery.php new file mode 100644 index 0000000..53330ec --- /dev/null +++ b/core/lib/Drupal/Core/Config/Schema/ConfigSchemaDiscovery.php @@ -0,0 +1,50 @@ +schemaStorage = $schema_storage; + } + + /** + * {@inheritdoc} + */ + public function getDefinitions() { + $definitions = array(); + foreach ($this->schemaStorage->readMultiple($this->schemaStorage->listAll()) as $schema) { + foreach ($schema as $type => $definition) { + $definitions[$type] = $definition; + } + } + return $definitions; + } +} diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index ba3f353..c025a20 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -9,6 +9,8 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Config\Schema\ConfigSchemaDiscovery; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\TypedData\TypedDataManager; /** @@ -17,13 +19,6 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerInterface { /** - * The cache ID for the definitions. - * - * @var string - */ - const CACHE_ID = 'typed_config_definitions'; - - /** * A storage instance for reading configuration data. * * @var \Drupal\Core\Config\StorageInterface @@ -45,13 +40,6 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI protected $definitions; /** - * Cache backend for the definitions. - * - * @var \Drupal\Core\Cache\CacheBackendInterface - */ - protected $cache; - - /** * Creates a new typed configuration manager. * * @param \Drupal\Core\Config\StorageInterface $configStorage @@ -61,10 +49,13 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend to use for caching the definitions. */ - public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, CacheBackendInterface $cache) { + public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler) { $this->configStorage = $configStorage; $this->schemaStorage = $schemaStorage; - $this->cache = $cache; + $this->setCacheBackend($cache, 'typed_config_definitions'); + $this->discovery = new ConfigSchemaDiscovery($schemaStorage); + $this->alterInfo('config_schema_info'); + $this->moduleHandler = $module_handler; } /** @@ -150,31 +141,9 @@ public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE) { /** * {@inheritdoc} */ - public function getDefinitions() { - if (!isset($this->definitions)) { - if ($cache = $this->cache->get($this::CACHE_ID)) { - $this->definitions = $cache->data; - } - else { - $this->definitions = array(); - foreach ($this->schemaStorage->readMultiple($this->schemaStorage->listAll()) as $schema) { - foreach ($schema as $type => $definition) { - $this->definitions[$type] = $definition; - } - } - $this->cache->set($this::CACHE_ID, $this->definitions); - } - } - return $this->definitions; - } - - /** - * {@inheritdoc} - */ public function clearCachedDefinitions() { - $this->definitions = NULL; $this->schemaStorage->reset(); - $this->cache->delete($this::CACHE_ID); + parent::clearCachedDefinitions(); } /** diff --git a/core/modules/config/src/Tests/DefaultConfigTest.php b/core/modules/config/src/Tests/DefaultConfigTest.php index f4ef065..25c5a01 100644 --- a/core/modules/config/src/Tests/DefaultConfigTest.php +++ b/core/modules/config/src/Tests/DefaultConfigTest.php @@ -46,7 +46,8 @@ public function testDefaultConfig() { $typed_config = new TypedConfigManager( \Drupal::service('config.storage'), new TestInstallStorage(InstallStorage::CONFIG_SCHEMA_DIRECTORY), - \Drupal::service('cache.discovery') + \Drupal::service('cache.discovery'), + \Drupal::service('module_handler') ); // Create a configuration storage with access to default configuration in diff --git a/core/modules/config_translation/config_translation.api.php b/core/modules/config_translation/config_translation.api.php index a7db185..27c89b1 100644 --- a/core/modules/config_translation/config_translation.api.php +++ b/core/modules/config_translation/config_translation.api.php @@ -89,24 +89,5 @@ function hook_config_translation_info_alter(&$info) { } /** - * Alter config typed data definitions. - * - * Used to automatically generate translation forms, you can alter the typed - * data types representing each configuration schema type to change default - * labels or form element renderers. - * - * @param $definitions - * Associative array of configuration type definitions keyed by schema type - * names. The elements are themselves array with information about the type. - */ -function hook_config_translation_type_info_alter(&$definitions) { - // Enhance the text and date type definitions with classes to generate proper - // form elements in ConfigTranslationFormBase. Other translatable types will - // appear as a one line textfield. - $definitions['text']['form_element_class'] = '\Drupal\config_translation\FormElement\Textarea'; - $definitions['date_format']['form_element_class'] = '\Drupal\config_translation\FormElement\DateFormat'; -} - -/** * @} End of "addtogroup hooks". */ diff --git a/core/modules/config_translation/config_translation.module b/core/modules/config_translation/config_translation.module index b128931..b0565b7 100644 --- a/core/modules/config_translation/config_translation.module +++ b/core/modules/config_translation/config_translation.module @@ -192,9 +192,9 @@ function config_translation_entity_operation(EntityInterface $entity) { } /** - * Implements hook_config_translation_type_info_alter(). + * Implements hook_config_schema_info_alter(). */ -function config_translation_config_translation_type_info_alter(&$definitions) { +function config_translation_config_schema_info_alter(&$definitions) { // Enhance the text and date type definitions with classes to generate proper // form elements in ConfigTranslationFormBase. Other translatable types will // appear as a one line textfield. diff --git a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php index 5b6125a..a14c585 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php @@ -49,13 +49,6 @@ protected $localeStorage; /** - * The module handler to invoke the alter hook. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** * The mapper for configuration translation. * * @var \Drupal\config_translation\ConfigMapperInterface @@ -99,14 +92,11 @@ * The configuration mapper manager. * @param \Drupal\locale\StringStorageInterface $locale_storage * The translation storage object. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler to invoke the alter hook. */ - public function __construct(TypedConfigManagerInterface $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler, ConfigurableLanguageManagerInterface $language_manager) { + public function __construct(TypedConfigManagerInterface $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ConfigurableLanguageManagerInterface $language_manager) { $this->typedConfigManager = $typed_config_manager; $this->configMapperManager = $config_mapper_manager; $this->localeStorage = $locale_storage; - $this->moduleHandler = $module_handler; $this->languageManager = $language_manager; } @@ -118,7 +108,6 @@ public static function create(ContainerInterface $container) { $container->get('config.typed'), $container->get('plugin.manager.config_translation.mapper'), $container->get('locale.storage'), - $container->get('module_handler'), $container->get('language_manager') ); } @@ -311,13 +300,6 @@ protected function buildConfigForm(Element $schema, $config_data, $base_config_d else { $definition = $element->getDataDefinition(); - // Invoke hook_config_translation_type_info_alter() implementations to - // alter the configuration types. - $definitions = array( - $definition['type'] => &$definition, - ); - $this->moduleHandler->alter('config_translation_type_info', $definitions); - // Create form element only for translatable items. if (!isset($definition['translatable']) || !isset($definition['type'])) { continue; diff --git a/core/modules/locale/locale.services.yml b/core/modules/locale/locale.services.yml index f7794c3..64a9a0b 100644 --- a/core/modules/locale/locale.services.yml +++ b/core/modules/locale/locale.services.yml @@ -1,7 +1,7 @@ services: locale.config.typed: class: Drupal\locale\LocaleConfigManager - arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage', '@cache.discovery', '@config.factory', '@language_manager'] + arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage', '@cache.discovery', '@config.factory', '@language_manager', '@module_handler'] locale.storage: class: Drupal\locale\StringDatabaseStorage arguments: ['@database'] diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index 5466558..5b7fb99 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\language\ConfigurableLanguageManagerInterface; @@ -71,9 +72,9 @@ class LocaleConfigManager extends TypedConfigManager { * @param \Drupal\language\ConfigurableLanguageManagerInterface * The language manager. */ - public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, StorageInterface $installStorage, StringStorageInterface $localeStorage, CacheBackendInterface $cache, ConfigFactoryInterface $config_factory, ConfigurableLanguageManagerInterface $language_manager) { + public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, StorageInterface $installStorage, StringStorageInterface $localeStorage, CacheBackendInterface $cache, ConfigFactoryInterface $config_factory, ConfigurableLanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler) { // Note we use the install storage for the parent constructor. - parent::__construct($configStorage, $schemaStorage, $cache); + parent::__construct($configStorage, $schemaStorage, $cache, $module_handler); $this->installStorage = $installStorage; $this->localeStorage = $localeStorage; $this->configFactory = $config_factory; diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index f3b4d97..1dd0db7 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -2841,6 +2841,25 @@ function hook_config_import_steps_alter(&$sync_steps, \Drupal\Core\Config\Config } /** + * Alter config typed data definitions. + * + * For example you can alter the typed data types representing each + * configuration schema type to change default labels or form element renderers + * used for configuration translation. + * + * @param $definitions + * Associative array of configuration type definitions keyed by schema type + * names. The elements are themselves array with information about the type. + */ +function hook_config_schema_info_alter(&$definitions) { + // Enhance the text and date type definitions with classes to generate proper + // form elements in ConfigTranslationFormBase. Other translatable types will + // appear as a one line textfield. + $definitions['text']['form_element_class'] = '\Drupal\config_translation\FormElement\Textarea'; + $definitions['date_format']['form_element_class'] = '\Drupal\config_translation\FormElement\DateFormat'; +} + +/** * @} End of "addtogroup hooks". */