function config_translation_config_translation_info

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

Implements hook_config_translation_info().

File

core/modules/config_translation/config_translation.module, line 104

Code

function config_translation_config_translation_info(&$info) {
    $entity_type_manager = \Drupal::entityTypeManager();
    // 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) {
            // Make sure entity type has field UI enabled and has a base route.
            if ($entity_type->get('field_ui_base_route')) {
                $info[$entity_type_id . '_fields'] = [
                    'base_route_name' => "entity.field_config.{$entity_type_id}_field_edit_form",
                    'entity_type' => 'field_config',
                    'class' => '\\Drupal\\config_translation\\ConfigFieldMapper',
                    'base_entity_type' => $entity_type_id,
                    'weight' => 10,
                ];
            }
        }
    }
    // Discover configuration entities automatically.
    foreach ($entity_type_manager->getDefinitions() as $entity_type_id => $entity_type) {
        // Determine base path for entities automatically if provided via the
        // configuration entity.
        if (!$entity_type->entityClassImplements(ConfigEntityInterface::class) || !$entity_type->hasLinkTemplate('edit-form')) {
            // Do not record this entity mapper if the entity type does not
            // provide a base route. We'll surely not be able to do anything with
            // it anyway. Configuration entities with a dynamic base path, such as
            // fields, need special treatment. See above.
            continue;
        }
        // Use the entity type as the plugin ID.
        $base_route_name = "entity.{$entity_type_id}.edit_form";
        $info[$entity_type_id] = [
            'class' => '\\Drupal\\config_translation\\ConfigEntityMapper',
            'base_route_name' => $base_route_name,
            'title' => $entity_type->getSingularLabel(),
            'names' => [],
            '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.