3 namespace Drupal\field_ui\Routing;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\Routing\Route;
11 * Enhances Field UI routes by adding proper information about the bundle name.
13 class FieldUiRouteEnhancer implements RouteEnhancerInterface {
18 * @var \Drupal\Core\Entity\EntityManagerInterface
20 protected $entityManager;
23 * Constructs a FieldUiRouteEnhancer object.
25 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
28 public function __construct(EntityManagerInterface $entity_manager) {
29 $this->entityManager = $entity_manager;
35 public function enhance(array $defaults, Request $request) {
36 if (($bundle = $this->entityManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType()) && isset($defaults[$bundle])) {
37 // Field UI forms only need the actual name of the bundle they're dealing
38 // with, not an upcasted entity object, so provide a simple way for them
40 $defaults['bundle'] = $defaults['_raw_variables']->get($bundle);
49 public function applies(Route $route) {
50 return ($route->hasOption('_field_ui'));