Same name and namespace in other branches
  1. 8.9.x core/modules/config_translation/src/ConfigEntityMapper.php \Drupal\config_translation\ConfigEntityMapper::setEntity()
  2. 9 core/modules/config_translation/src/ConfigEntityMapper.php \Drupal\config_translation\ConfigEntityMapper::setEntity()

Sets the entity instance for this mapper.

This method can only be invoked when the concrete entity is known, that is in a request for an entity translation path. After this method is called, the mapper is fully populated with the proper display title and configuration names to use to check permissions or display a translation screen.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The configuration entity to set.

Return value

bool TRUE, if the entity was set successfully; FALSE otherwise.

Overrides ConfigEntityMapperInterface::setEntity

3 calls to ConfigEntityMapper::setEntity()
ConfigEntityMapper::populateFromRouteMatch in core/modules/config_translation/src/ConfigEntityMapper.php
Populate the config mapper with route match data.
ConfigFieldMapper::setEntity in core/modules/config_translation/src/ConfigFieldMapper.php
Sets the entity instance for this mapper.
NodeTypeMapper::setEntity in core/modules/node/src/ConfigTranslation/NodeTypeMapper.php
Sets the entity instance for this mapper.
2 methods override ConfigEntityMapper::setEntity()
ConfigFieldMapper::setEntity in core/modules/config_translation/src/ConfigFieldMapper.php
Sets the entity instance for this mapper.
NodeTypeMapper::setEntity in core/modules/node/src/ConfigTranslation/NodeTypeMapper.php
Sets the entity instance for this mapper.

File

core/modules/config_translation/src/ConfigEntityMapper.php, line 127

Class

ConfigEntityMapper
Configuration mapper for configuration entities.

Namespace

Drupal\config_translation

Code

public function setEntity(ConfigEntityInterface $entity) {
  if (isset($this->entity)) {
    return FALSE;
  }
  $this->entity = $entity;

  // Add the list of configuration IDs belonging to this entity. We add on a
  // possibly existing list of names. This allows modules to alter the entity
  // page with more names if form altering added more configuration to an
  // entity. This is not a Drupal 8 best practice (ideally the configuration
  // would have pluggable components), but this may happen as well.

  /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type_info */
  $entity_type_info = $this->entityTypeManager
    ->getDefinition($this->entityType);
  $this
    ->addConfigName($entity_type_info
    ->getConfigPrefix() . '.' . $entity
    ->id());
  return TRUE;
}