Same filename in this branch
- 10 core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php
- 10 core/lib/Drupal/Core/ProxyClass/ParamConverter/AdminPathConfigEntityConverter.php
Same filename and directory in other branches
- 8.9.x core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php
- 9 core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php
Namespace
Drupal\Core\ParamConverter
File
core/lib/Drupal/Core/ParamConverter/AdminPathConfigEntityConverter.php
View source
<?php
namespace Drupal\Core\ParamConverter;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\AdminContext;
use Symfony\Component\Routing\Route;
class AdminPathConfigEntityConverter extends EntityConverter {
protected $configFactory;
protected $adminContext;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, AdminContext $admin_context, $entity_repository = NULL) {
parent::__construct($entity_type_manager, $entity_repository);
$this->configFactory = $config_factory;
$this->adminContext = $admin_context;
}
public function convert($value, $definition, $name, array $defaults) {
$entity_type_id = $this
->getEntityTypeFromDefaults($definition, $name, $defaults);
if (!$this->entityTypeManager
->hasDefinition($entity_type_id)) {
return NULL;
}
if (str_starts_with($definition['type'], 'entity:{')) {
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
if (!$entity_type
->entityClassImplements(ConfigEntityInterface::class)) {
return parent::convert($value, $definition, $name, $defaults);
}
}
if ($storage = $this->entityTypeManager
->getStorage($entity_type_id)) {
return $storage
->loadOverrideFree($value);
}
}
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 (str_starts_with($entity_type_id, '{')) {
return TRUE;
}
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
if ($entity_type
->entityClassImplements(ConfigEntityInterface::class)) {
return $this->adminContext
->isAdminRoute($route);
}
}
return FALSE;
}
}
Classes