annotate core/modules/config_translation/config_translation.api.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Hooks provided by the Configuration Translation module.
Chris@0 6 */
Chris@0 7
Chris@0 8 /**
Chris@0 9 * @addtogroup hooks
Chris@0 10 * @{
Chris@0 11 */
Chris@0 12
Chris@0 13 /**
Chris@0 14 * Introduce dynamic translation tabs for translation of configuration.
Chris@0 15 *
Chris@0 16 * This hook augments MODULE.config_translation.yml as well as
Chris@0 17 * THEME.config_translation.yml files to collect dynamic translation mapper
Chris@0 18 * information. If your information is static, just provide such a YAML file
Chris@0 19 * with your module containing the mapping.
Chris@0 20 *
Chris@0 21 * Note that while themes can provide THEME.config_translation.yml files this
Chris@0 22 * hook is not invoked for themes.
Chris@0 23 *
Chris@0 24 * @param array $info
Chris@0 25 * An associative array of configuration mapper information. Use an entity
Chris@0 26 * name for the key (for entity mapping) or a unique string for configuration
Chris@0 27 * name list mapping. The values of the associative array are arrays
Chris@0 28 * themselves in the same structure as the *.config_translation.yml files.
Chris@0 29 *
Chris@0 30 * @see hook_config_translation_info_alter()
Chris@0 31 * @see \Drupal\config_translation\ConfigMapperManagerInterface
Chris@0 32 * @see \Drupal\config_translation\Routing\RouteSubscriber::routes()
Chris@0 33 */
Chris@0 34 function hook_config_translation_info(&$info) {
Chris@0 35 $entity_manager = \Drupal::entityManager();
Chris@0 36 $route_provider = \Drupal::service('router.route_provider');
Chris@0 37
Chris@0 38 // If field UI is not enabled, the base routes of the type
Chris@0 39 // "entity.field_config.{$entity_type}_field_edit_form" are not defined.
Chris@0 40 if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
Chris@0 41 // Add fields entity mappers to all fieldable entity types defined.
Chris@0 42 foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
Chris@0 43 $base_route = NULL;
Chris@0 44 try {
Chris@0 45 $base_route = $route_provider->getRouteByName('entity.field_config.' . $entity_type_id . '_field_edit_form');
Chris@0 46 }
Chris@0 47 catch (RouteNotFoundException $e) {
Chris@0 48 // Ignore non-existent routes.
Chris@0 49 }
Chris@0 50
Chris@0 51 // Make sure entity type has field UI enabled and has a base route.
Chris@0 52 if ($entity_type->get('field_ui_base_route') && !empty($base_route)) {
Chris@0 53 $info[$entity_type_id . '_fields'] = [
Chris@0 54 'base_route_name' => 'entity.field_config.' . $entity_type_id . '_field_edit_form',
Chris@0 55 'entity_type' => 'field_config',
Chris@0 56 'title' => t('Title'),
Chris@0 57 'class' => '\Drupal\config_translation\ConfigFieldMapper',
Chris@0 58 'base_entity_type' => $entity_type_id,
Chris@0 59 'weight' => 10,
Chris@0 60 ];
Chris@0 61 }
Chris@0 62 }
Chris@0 63 }
Chris@0 64 }
Chris@0 65
Chris@0 66 /**
Chris@0 67 * Alter existing translation tabs for translation of configuration.
Chris@0 68 *
Chris@0 69 * This hook is useful to extend existing configuration mappers with new
Chris@0 70 * configuration names, for example when altering existing forms with new
Chris@0 71 * settings stored elsewhere. This allows the translation experience to also
Chris@0 72 * reflect the compound form element in one screen.
Chris@0 73 *
Chris@0 74 * @param array $info
Chris@0 75 * An associative array of discovered configuration mappers. Use an entity
Chris@0 76 * name for the key (for entity mapping) or a unique string for configuration
Chris@0 77 * name list mapping. The values of the associative array are arrays
Chris@0 78 * themselves in the same structure as the *.config_translation.yml files.
Chris@0 79 *
Chris@0 80 * @see hook_translation_info()
Chris@0 81 * @see \Drupal\config_translation\ConfigMapperManagerInterface
Chris@0 82 */
Chris@0 83 function hook_config_translation_info_alter(&$info) {
Chris@0 84 // Add additional site settings to the site information screen, so it shows
Chris@0 85 // up on the translation screen. (Form alter in the elements whose values are
Chris@0 86 // stored in this config file using regular form altering on the original
Chris@0 87 // configuration form.)
Chris@0 88 $info['system.site_information_settings']['names'][] = 'example.site.setting';
Chris@0 89 }
Chris@0 90
Chris@0 91 /**
Chris@0 92 * @} End of "addtogroup hooks".
Chris@0 93 */