3 namespace Drupal\field_ui\Routing;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Routing\EnhancerInterface;
7 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
8 use Symfony\Component\HttpFoundation\Request;
9 use Symfony\Component\Routing\Route;
12 * Enhances Field UI routes by adding proper information about the bundle name.
14 class FieldUiRouteEnhancer implements EnhancerInterface {
19 * @var \Drupal\Core\Entity\EntityManagerInterface
21 protected $entityManager;
24 * Constructs a FieldUiRouteEnhancer object.
26 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
29 public function __construct(EntityManagerInterface $entity_manager) {
30 $this->entityManager = $entity_manager;
36 public function enhance(array $defaults, Request $request) {
37 if (!$this->applies($defaults[RouteObjectInterface::ROUTE_OBJECT])) {
41 if (($bundle = $this->entityManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType()) && isset($defaults[$bundle])) {
42 // Field UI forms only need the actual name of the bundle they're dealing
43 // with, not an upcasted entity object, so provide a simple way for them
45 $defaults['bundle'] = $defaults['_raw_variables']->get($bundle);
54 protected function applies(Route $route) {
55 return ($route->hasOption('_field_ui'));