class ConfigEntityMapper in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/config_translation/src/ConfigEntityMapper.php \Drupal\config_translation\ConfigEntityMapper
Configuration mapper for configuration entities.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\config_translation\ConfigNamesMapper implements ConfigMapperInterface, ContainerFactoryPluginInterface
- class \Drupal\config_translation\ConfigEntityMapper
- class \Drupal\config_translation\ConfigNamesMapper implements ConfigMapperInterface, ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of ConfigEntityMapper
2 files declare their use of ConfigEntityMapper
- ConfigEntityMapperTest.php in core/
modules/ config_translation/ tests/ src/ Unit/ ConfigEntityMapperTest.php - Contains \Drupal\Tests\config_translation\Unit\ConfigEntityMapperTest.
- NodeTypeMapper.php in core/
modules/ node/ src/ ConfigTranslation/ NodeTypeMapper.php - Contains \Drupal\node\ConfigTranslation\NodeTypeMapper.
File
- core/
modules/ config_translation/ src/ ConfigEntityMapper.php, line 26 - Contains \Drupal\config_translation\ConfigEntityMapper.
Namespace
Drupal\config_translationView source
class ConfigEntityMapper extends ConfigNamesMapper {
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Configuration entity type name.
*
* @var string
*/
protected $entityType;
/**
* Loaded entity instance to help produce the translation interface.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityInterface
*/
protected $entity;
/**
* The label for the entity type.
*
* @var string
*/
protected $typeLabel;
/**
* Constructs a ConfigEntityMapper.
*
* @param string $plugin_id
* The config mapper plugin ID.
* @param mixed $plugin_definition
* An array of plugin information as documented in
* ConfigNamesMapper::__construct() with the following additional keys:
* - entity_type: The name of the entity type this mapper belongs to.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager.
* @param \Drupal\locale\LocaleConfigManager $locale_config_manager
* The locale configuration manager.
* @param \Drupal\config_translation\ConfigMapperManagerInterface $config_mapper_manager
* The mapper plugin discovery service.
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager
* The string translation manager.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $translation_manager, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
parent::__construct($plugin_id, $plugin_definition, $config_factory, $typed_config, $locale_config_manager, $config_mapper_manager, $route_provider, $translation_manager, $language_manager);
$this
->setType($plugin_definition['entity_type']);
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
// Note that we ignore the plugin $configuration because mappers have
// nothing to configure in themselves.
return new static($plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('config.typed'), $container
->get('locale.config_manager'), $container
->get('plugin.manager.config_translation.mapper'), $container
->get('router.route_provider'), $container
->get('string_translation'), $container
->get('entity.manager'), $container
->get('language_manager'));
}
/**
* {@inheritdoc}
*/
public function populateFromRouteMatch(RouteMatchInterface $route_match) {
parent::populateFromRouteMatch($route_match);
$entity = $route_match
->getParameter($this->entityType);
$this
->setEntity($entity);
}
/**
* Gets the entity instance for this mapper.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* The configuration entity.
*/
public function getEntity() {
return $this->entity;
}
/**
* 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.
*
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* The configuration entity to set.
*
* @return bool
* TRUE, if the entity was set successfully; FALSE otherwise.
*/
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->entityManager
->getDefinition($this->entityType);
$this
->addConfigName($entity_type_info
->getConfigPrefix() . '.' . $entity
->id());
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getTitle() {
return $this->entity
->label() . ' ' . $this->pluginDefinition['title'];
}
/**
* {@inheritdoc}
*/
public function getBaseRouteParameters() {
return array(
$this->entityType => $this->entity
->id(),
);
}
/**
* Set entity type for this mapper.
*
* This should be set in initialization. A mapper that knows its type but
* not yet its names is still useful for router item and tab generation. The
* concrete entity only turns out later with actual controller invocations,
* when the setEntity() method is invoked before the rest of the methods are
* used.
*
* @param string $entity_type
* The entity type to set.
*
* @return bool
* TRUE if the entity type was set correctly; FALSE otherwise.
*/
public function setType($entity_type) {
if (isset($this->entityType)) {
return FALSE;
}
$this->entityType = $entity_type;
return TRUE;
}
/**
* Gets the entity type from this mapper.
*
* @return string
*/
public function getType() {
return $this->entityType;
}
/**
* {@inheritdoc}
*/
public function getTypeName() {
$entity_type_info = $this->entityManager
->getDefinition($this->entityType);
return $entity_type_info
->getLabel();
}
/**
* {@inheritdoc}
*/
public function getTypeLabel() {
$entityType = $this->entityManager
->getDefinition($this->entityType);
return $entityType
->getLabel();
}
/**
* {@inheritdoc}
*/
public function getOperations() {
return array(
'list' => array(
'title' => $this
->t('List'),
'url' => Url::fromRoute('config_translation.entity_list', [
'mapper_id' => $this
->getPluginId(),
]),
),
);
}
/**
* {@inheritdoc}
*/
public function getContextualLinkGroup() {
// @todo Contextual groups do not map to entity types in a predictable
// way. See https://www.drupal.org/node/2134841 to make them predictable.
switch ($this->entityType) {
case 'menu':
case 'block':
return $this->entityType;
case 'view':
return 'entity.view.edit_form';
default:
return NULL;
}
}
/**
* {@inheritdoc}
*/
public function getOverviewRouteName() {
return 'entity.' . $this->entityType . '.config_translation_overview';
}
/**
* {@inheritdoc}
*/
protected function processRoute(Route $route) {
// Add entity upcasting information.
$parameters = $route
->getOption('parameters') ?: array();
$parameters += array(
$this->entityType => array(
'type' => 'entity:' . $this->entityType,
),
);
$route
->setOption('parameters', $parameters);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigEntityMapper:: |
protected | property | Loaded entity instance to help produce the translation interface. | 1 |
ConfigEntityMapper:: |
protected | property | The entity manager. | |
ConfigEntityMapper:: |
protected | property | Configuration entity type name. | |
ConfigEntityMapper:: |
protected | property | The label for the entity type. | |
ConfigEntityMapper:: |
public static | function |
Creates an instance of the plugin. Overrides ConfigNamesMapper:: |
|
ConfigEntityMapper:: |
public | function |
Returns the route parameters for the base route the mapper is attached to. Overrides ConfigNamesMapper:: |
1 |
ConfigEntityMapper:: |
public | function |
Returns the name of the contextual link group to add contextual links to. Overrides ConfigNamesMapper:: |
|
ConfigEntityMapper:: |
public | function | Gets the entity instance for this mapper. | |
ConfigEntityMapper:: |
public | function |
Provides an array of information to build a list of operation links. Overrides ConfigNamesMapper:: |
|
ConfigEntityMapper:: |
public | function |
Returns route name for the translation overview route. Overrides ConfigNamesMapper:: |
1 |
ConfigEntityMapper:: |
public | function |
Returns title of this translation page. Overrides ConfigNamesMapper:: |
|
ConfigEntityMapper:: |
public | function | Gets the entity type from this mapper. | |
ConfigEntityMapper:: |
public | function |
Returns the label of the type of data the mapper encapsulates. Overrides ConfigNamesMapper:: |
1 |
ConfigEntityMapper:: |
public | function |
Returns the name of the type of data the mapper encapsulates. Overrides ConfigNamesMapper:: |
|
ConfigEntityMapper:: |
public | function |
Populate the config mapper with request data. Overrides ConfigNamesMapper:: |
|
ConfigEntityMapper:: |
protected | function |
Allows to process all config translation routes. Overrides ConfigNamesMapper:: |
|
ConfigEntityMapper:: |
public | function | Sets the entity instance for this mapper. | 2 |
ConfigEntityMapper:: |
public | function | Set entity type for this mapper. | |
ConfigEntityMapper:: |
public | function |
Constructs a ConfigEntityMapper. Overrides ConfigNamesMapper:: |
|
ConfigNamesMapper:: |
protected | property | The base route object that the mapper is attached to. | |
ConfigNamesMapper:: |
protected | property | The configuration factory. | |
ConfigNamesMapper:: |
protected | property | The mapper plugin discovery service. | |
ConfigNamesMapper:: |
protected | property | The language code of the language this mapper, if any. | |
ConfigNamesMapper:: |
protected | property | The language manager. | |
ConfigNamesMapper:: |
protected | property | The typed configuration manager. | |
ConfigNamesMapper:: |
protected | property | The available routes. | |
ConfigNamesMapper:: |
protected | property | The route provider. | |
ConfigNamesMapper:: |
protected | property | The typed config manager. | |
ConfigNamesMapper:: |
public | function |
Adds the given configuration name to the list of names. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the route object for a translation add form route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns route name for the translation add form route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the route parameters for the translation add form route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns a processed path for the base route the mapper is attached to. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the base route object the mapper is attached to. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the name of the base route the mapper is attached to. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns an array with all configuration data. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns an array of configuration names for the mapper. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the route object for the translation deletion route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns route name for the translation deletion route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the route parameters for the translation deletion route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the route object for a translation edit form route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns route name for the translation edit form route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the route parameters for the translation edit form route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the original language code of the configuration. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns a processed path for the translation overview route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the route object for a translation overview route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the route parameters for the translation overview route. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Returns the weight of the mapper. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Checks that all pieces of this configuration mapper have a schema. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Checks if pieces of this configuration mapper have translatables. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Checks whether there is already a translation for this mapper. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Sets the original language code. Overrides ConfigMapperInterface:: |
|
ConfigNamesMapper:: |
public | function |
Sets the route collection. Overrides ConfigMapperInterface:: |
|
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 2 |
PluginBase:: |
protected | property | The plugin implementation definition. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |