FieldUiRouteEnhancer.php in Drupal 8
File
core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php
View source
<?php
namespace Drupal\field_ui\Routing;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Routing\EnhancerInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
class FieldUiRouteEnhancer implements EnhancerInterface {
use DeprecatedServicePropertyTrait;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
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');
}
}