EntityBundleRouteEnhancer.php in Drupal 10
File
core/lib/Drupal/Core/Entity/Enhancer/EntityBundleRouteEnhancer.php
View source
<?php
namespace Drupal\Core\Entity\Enhancer;
use Drupal\Core\Routing\EnhancerInterface;
use Drupal\Core\Routing\RouteObjectInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
class EntityBundleRouteEnhancer implements EnhancerInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public function enhance(array $defaults, Request $request) {
if (!$this
->applies($defaults[RouteObjectInterface::ROUTE_OBJECT])) {
return $defaults;
}
if (($bundle = $this->entityTypeManager
->getDefinition($defaults['entity_type_id'])
->getBundleEntityType()) && isset($defaults[$bundle])) {
$defaults['bundle'] = $defaults['_raw_variables']
->get($bundle);
}
return $defaults;
}
protected function applies(Route $route) {
return $route
->hasOption('_field_ui');
}
}