class AdminPathConfigEntityConverter in Zircon Profile 8
Same name in this branch
- 8 core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php \Drupal\Core\ParamConverter\AdminPathConfigEntityConverter
- 8 core/lib/Drupal/Core/ProxyClass/ParamConverter/AdminPathConfigEntityConverter.php \Drupal\Core\ProxyClass\ParamConverter\AdminPathConfigEntityConverter
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php \Drupal\Core\ParamConverter\AdminPathConfigEntityConverter
Makes sure the unmodified ConfigEntity is loaded on admin pages.
Converts entity route arguments to unmodified entities as opposed to converting to entities with overrides, such as the negotiated language.
This converter applies only if the path is an admin path, the entity is a config entity, and the "with_config_overrides" element is not set to TRUE on the parameter definition.
Due to this converter having a higher weight than the default EntityConverter, every time this applies, it takes over the conversion duty from EntityConverter. As we only allow a single converter per route argument, EntityConverter is ignored when this converter applies.
Hierarchy
- class \Drupal\Core\ParamConverter\EntityConverter implements ParamConverterInterface
- class \Drupal\Core\ParamConverter\AdminPathConfigEntityConverter
Expanded class hierarchy of AdminPathConfigEntityConverter
1 string reference to 'AdminPathConfigEntityConverter'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses AdminPathConfigEntityConverter
File
- core/
lib/ Drupal/ Core/ ParamConverter/ AdminPathConfigEntityConverter.php, line 30 - Contains \Drupal\Core\ParamConverter\AdminPathConfigEntityConverter.
Namespace
Drupal\Core\ParamConverterView source
class AdminPathConfigEntityConverter extends EntityConverter {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The route admin context to determine whether a route is an admin one.
*
* @var \Drupal\Core\Routing\AdminContext
*/
protected $adminContext;
/**
* Constructs a new EntityConverter.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Routing\AdminContext $admin_context
* The route admin context service.
*
*/
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, AdminContext $admin_context) {
parent::__construct($entity_manager);
$this->configFactory = $config_factory;
$this->adminContext = $admin_context;
}
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults) {
$entity_type_id = $this
->getEntityTypeFromDefaults($definition, $name, $defaults);
// If the entity type is dynamic, confirm it to be a config entity. Static
// entity types will have performed this check in self::applies().
if (strpos($definition['type'], 'entity:{') === 0) {
$entity_type = $this->entityManager
->getDefinition($entity_type_id);
if (!$entity_type
->isSubclassOf('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
return parent::convert($value, $definition, $name, $defaults);
}
}
if ($storage = $this->entityManager
->getStorage($entity_type_id)) {
// Make sure no overrides are loaded.
return $storage
->loadOverrideFree($value);
}
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
if (isset($definition['with_config_overrides']) && $definition['with_config_overrides']) {
return FALSE;
}
if (parent::applies($definition, $name, $route)) {
$entity_type_id = substr($definition['type'], strlen('entity:'));
// If the entity type is dynamic, defer checking to self::convert().
if (strpos($entity_type_id, '{') === 0) {
return TRUE;
}
// As we only want to override EntityConverter for ConfigEntities, find
// out whether the current entity is a ConfigEntity.
$entity_type = $this->entityManager
->getDefinition($entity_type_id);
if ($entity_type
->isSubclassOf('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
return $this->adminContext
->isAdminRoute($route);
}
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdminPathConfigEntityConverter:: |
protected | property | The route admin context to determine whether a route is an admin one. | |
AdminPathConfigEntityConverter:: |
protected | property | The config factory. | |
AdminPathConfigEntityConverter:: |
public | function |
Determines if the converter applies to a specific route and variable. Overrides EntityConverter:: |
|
AdminPathConfigEntityConverter:: |
public | function |
Converts path variables to their corresponding objects. Overrides EntityConverter:: |
|
AdminPathConfigEntityConverter:: |
public | function |
Constructs a new EntityConverter. Overrides EntityConverter:: |
|
EntityConverter:: |
protected | property | Entity manager which performs the upcasting in the end. | |
EntityConverter:: |
protected | function | Determines the entity type ID given a route definition and route defaults. |