class ConfigFieldMapper

Same name in other branches
  1. 9 core/modules/config_translation/src/ConfigFieldMapper.php \Drupal\config_translation\ConfigFieldMapper
  2. 8.9.x core/modules/config_translation/src/ConfigFieldMapper.php \Drupal\config_translation\ConfigFieldMapper
  3. 11.x core/modules/config_translation/src/ConfigFieldMapper.php \Drupal\config_translation\ConfigFieldMapper

Configuration mapper for fields.

On top of plugin definition values on ConfigEntityMapper, the plugin definition for field mappers are required to contain the following additional keys:

  • base_entity_type: The name of the entity type the fields are attached to.

Hierarchy

Expanded class hierarchy of ConfigFieldMapper

1 file declares its use of ConfigFieldMapper
ConfigFieldMapperTest.php in core/modules/config_translation/tests/src/Unit/ConfigFieldMapperTest.php

File

core/modules/config_translation/src/ConfigFieldMapper.php, line 15

Namespace

Drupal\config_translation
View source
class ConfigFieldMapper extends ConfigEntityMapper {
    
    /**
     * Loaded entity instance to help produce the translation interface.
     *
     * @var \Drupal\field\FieldConfigInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    public function getBaseRouteParameters() {
        $parameters = parent::getBaseRouteParameters();
        $base_entity_info = $this->entityTypeManager
            ->getDefinition($this->pluginDefinition['base_entity_type']);
        $bundle_parameter_key = $base_entity_info->getBundleEntityType() ?: 'bundle';
        $parameters[$bundle_parameter_key] = $this->entity
            ->getTargetBundle();
        return $parameters;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getOverviewRouteName() {
        return 'entity.field_config.config_translation_overview.' . $this->pluginDefinition['base_entity_type'];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getTypeLabel() {
        $base_entity_info = $this->entityTypeManager
            ->getDefinition($this->pluginDefinition['base_entity_type']);
        return $this->t('@label fields', [
            '@label' => $base_entity_info->getLabel(),
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function setEntity(ConfigEntityInterface $entity) {
        if (parent::setEntity($entity)) {
            // Field storage config can also contain translatable values. Add the name
            // of the config as well to the list of configs for this entity.
            
            /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
            $field_storage = $this->entity
                ->getFieldStorageDefinition();
            
            /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type_info */
            $entity_type_info = $this->entityTypeManager
                ->getDefinition($field_storage->getEntityTypeId());
            $this->addConfigName($entity_type_info->getConfigPrefix() . '.' . $field_storage->id());
            return TRUE;
        }
        return FALSE;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ConfigEntityMapper::$entityType protected property Configuration entity type name.
ConfigEntityMapper::$entityTypeManager protected property The entity type manager.
ConfigEntityMapper::$typeLabel protected property The label for the entity type.
ConfigEntityMapper::create public static function Overrides ConfigNamesMapper::create
ConfigEntityMapper::getContextualLinkGroup public function Overrides ConfigNamesMapper::getContextualLinkGroup
ConfigEntityMapper::getEntity public function Overrides ConfigEntityMapperInterface::getEntity
ConfigEntityMapper::getOperations public function Overrides ConfigNamesMapper::getOperations
ConfigEntityMapper::getTitle public function Overrides ConfigNamesMapper::getTitle
ConfigEntityMapper::getType public function Overrides ConfigEntityMapperInterface::getType
ConfigEntityMapper::getTypeName public function Overrides ConfigNamesMapper::getTypeName
ConfigEntityMapper::populateFromRouteMatch public function Overrides ConfigNamesMapper::populateFromRouteMatch
ConfigEntityMapper::processRoute protected function Overrides ConfigNamesMapper::processRoute
ConfigEntityMapper::setType public function Overrides ConfigEntityMapperInterface::setType
ConfigEntityMapper::__construct public function Constructs a ConfigEntityMapper. Overrides ConfigNamesMapper::__construct
ConfigFieldMapper::$entity protected property Loaded entity instance to help produce the translation interface. Overrides ConfigEntityMapper::$entity
ConfigFieldMapper::getBaseRouteParameters public function Overrides ConfigEntityMapper::getBaseRouteParameters
ConfigFieldMapper::getOverviewRouteName public function Overrides ConfigEntityMapper::getOverviewRouteName
ConfigFieldMapper::getTypeLabel public function Overrides ConfigEntityMapper::getTypeLabel
ConfigFieldMapper::setEntity public function Overrides ConfigEntityMapper::setEntity
ConfigNamesMapper::$baseRoute protected property The base route object that the mapper is attached to.
ConfigNamesMapper::$configFactory protected property The configuration factory.
ConfigNamesMapper::$configMapperManager protected property The mapper plugin discovery service.
ConfigNamesMapper::$eventDispatcher protected property The event dispatcher.
ConfigNamesMapper::$langcode protected property The language code of the language this mapper, if any.
ConfigNamesMapper::$languageManager protected property The language manager.
ConfigNamesMapper::$localeConfigManager protected property The typed configuration manager.
ConfigNamesMapper::$routeCollection protected property The available routes.
ConfigNamesMapper::$routeProvider protected property The route provider.
ConfigNamesMapper::$typedConfigManager protected property The typed config manager.
ConfigNamesMapper::addConfigName public function Overrides ConfigMapperInterface::addConfigName
ConfigNamesMapper::getAddRoute public function Overrides ConfigMapperInterface::getAddRoute
ConfigNamesMapper::getAddRouteName public function Overrides ConfigMapperInterface::getAddRouteName
ConfigNamesMapper::getAddRouteParameters public function Overrides ConfigMapperInterface::getAddRouteParameters
ConfigNamesMapper::getBasePath public function Overrides ConfigMapperInterface::getBasePath
ConfigNamesMapper::getBaseRoute public function Overrides ConfigMapperInterface::getBaseRoute
ConfigNamesMapper::getBaseRouteName public function Overrides ConfigMapperInterface::getBaseRouteName
ConfigNamesMapper::getConfigData public function Overrides ConfigMapperInterface::getConfigData
ConfigNamesMapper::getConfigNames public function Overrides ConfigMapperInterface::getConfigNames
ConfigNamesMapper::getDeleteRoute public function Overrides ConfigMapperInterface::getDeleteRoute
ConfigNamesMapper::getDeleteRouteName public function Overrides ConfigMapperInterface::getDeleteRouteName
ConfigNamesMapper::getDeleteRouteParameters public function Overrides ConfigMapperInterface::getDeleteRouteParameters
ConfigNamesMapper::getEditRoute public function Overrides ConfigMapperInterface::getEditRoute
ConfigNamesMapper::getEditRouteName public function Overrides ConfigMapperInterface::getEditRouteName
ConfigNamesMapper::getEditRouteParameters public function Overrides ConfigMapperInterface::getEditRouteParameters
ConfigNamesMapper::getLangcode public function Overrides ConfigMapperInterface::getLangcode
ConfigNamesMapper::getLangcodeFromConfig public function Overrides ConfigMapperInterface::getLangcodeFromConfig
ConfigNamesMapper::getOverviewPath public function Overrides ConfigMapperInterface::getOverviewPath
ConfigNamesMapper::getOverviewRoute public function Overrides ConfigMapperInterface::getOverviewRoute
ConfigNamesMapper::getOverviewRouteParameters public function Overrides ConfigMapperInterface::getOverviewRouteParameters
ConfigNamesMapper::getWeight public function Overrides ConfigMapperInterface::getWeight
ConfigNamesMapper::hasSchema public function Overrides ConfigMapperInterface::hasSchema
ConfigNamesMapper::hasTranslatable public function Overrides ConfigMapperInterface::hasTranslatable
ConfigNamesMapper::hasTranslation public function Overrides ConfigMapperInterface::hasTranslation
ConfigNamesMapper::setLangcode public function Overrides ConfigMapperInterface::setLangcode
ConfigNamesMapper::setRouteCollection public function Overrides ConfigMapperInterface::setRouteCollection

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