You are here

public function ConfigEntityMapper::setEntity in Drupal 10

Same name and namespace in other branches
  1. 8 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.

File

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

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;
}