comparison core/modules/config_translation/config_translation.api.php @ 0:4c8ae668cc8c

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