function hook_config_translation_info

Same name and namespace in other branches
  1. 9 core/modules/config_translation/config_translation.api.php \hook_config_translation_info()
  2. 8.9.x core/modules/config_translation/config_translation.api.php \hook_config_translation_info()
  3. 10 core/modules/config_translation/config_translation.api.php \hook_config_translation_info()

Introduce dynamic translation tabs for translation of configuration.

This hook augments MODULE.config_translation.yml as well as THEME.config_translation.yml files to collect dynamic translation mapper information. If your information is static, just provide such a YAML file with your module containing the mapping.

Note that while themes can provide THEME.config_translation.yml files this hook is not invoked for themes.

Parameters

array $info: An associative array of configuration mapper information. Use an entity name for the key (for entity mapping) or a unique string for configuration name list mapping. The values of the associative array are arrays themselves in the same structure as the *.config_translation.yml files.

See also

hook_config_translation_info_alter()

\Drupal\config_translation\ConfigMapperManagerInterface

\Drupal\config_translation\Routing\RouteSubscriber::routes()

Related topics

1 function implements hook_config_translation_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

config_translation_config_translation_info in core/modules/config_translation/config_translation.module
Implements hook_config_translation_info().

File

core/modules/config_translation/config_translation.api.php, line 34

Code

function hook_config_translation_info(&$info) {
    $entity_type_manager = \Drupal::entityTypeManager();
    $route_provider = \Drupal::service('router.route_provider');
    // If field UI is not enabled, the base routes of the type
    // "entity.field_config.{$entity_type}_field_edit_form" are not defined.
    if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
        // Add fields entity mappers to all fieldable entity types defined.
        foreach ($entity_type_manager->getDefinitions() as $entity_type_id => $entity_type) {
            $base_route = NULL;
            try {
                $base_route = $route_provider->getRouteByName('entity.field_config.' . $entity_type_id . '_field_edit_form');
            } catch (RouteNotFoundException $e) {
                // Ignore non-existent routes.
            }
            // Make sure entity type has field UI enabled and has a base route.
            if ($entity_type->get('field_ui_base_route') && !empty($base_route)) {
                $info[$entity_type_id . '_fields'] = [
                    'base_route_name' => 'entity.field_config.' . $entity_type_id . '_field_edit_form',
                    'entity_type' => 'field_config',
                    'title' => t('Title'),
                    'class' => '\\Drupal\\config_translation\\ConfigFieldMapper',
                    'base_entity_type' => $entity_type_id,
                    'weight' => 10,
                ];
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.