comparison core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\field_ui\Routing;
4
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;
9
10 /**
11 * Enhances Field UI routes by adding proper information about the bundle name.
12 */
13 class FieldUiRouteEnhancer implements RouteEnhancerInterface {
14
15 /**
16 * The entity manager.
17 *
18 * @var \Drupal\Core\Entity\EntityManagerInterface
19 */
20 protected $entityManager;
21
22 /**
23 * Constructs a FieldUiRouteEnhancer object.
24 *
25 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
26 * The entity manager.
27 */
28 public function __construct(EntityManagerInterface $entity_manager) {
29 $this->entityManager = $entity_manager;
30 }
31
32 /**
33 * {@inheritdoc}
34 */
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
39 // to get it.
40 $defaults['bundle'] = $defaults['_raw_variables']->get($bundle);
41 }
42
43 return $defaults;
44 }
45
46 /**
47 * {@inheritdoc}
48 */
49 public function applies(Route $route) {
50 return ($route->hasOption('_field_ui'));
51 }
52
53 }