annotate core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\field_ui\Routing;
Chris@0 4
Chris@18 5 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
Chris@14 6 use Drupal\Core\Routing\EnhancerInterface;
Chris@14 7 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
Chris@18 8 use Drupal\Core\Entity\EntityTypeManagerInterface;
Chris@0 9 use Symfony\Component\HttpFoundation\Request;
Chris@0 10 use Symfony\Component\Routing\Route;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Enhances Field UI routes by adding proper information about the bundle name.
Chris@0 14 */
Chris@14 15 class FieldUiRouteEnhancer implements EnhancerInterface {
Chris@18 16 use DeprecatedServicePropertyTrait;
Chris@0 17
Chris@0 18 /**
Chris@18 19 * {@inheritdoc}
Chris@18 20 */
Chris@18 21 protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
Chris@18 22
Chris@18 23 /**
Chris@18 24 * The entity type manager service.
Chris@0 25 *
Chris@18 26 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
Chris@0 27 */
Chris@18 28 protected $entityTypeManager;
Chris@0 29
Chris@0 30 /**
Chris@0 31 * Constructs a FieldUiRouteEnhancer object.
Chris@0 32 *
Chris@18 33 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
Chris@18 34 * The entity type manager service.
Chris@0 35 */
Chris@18 36 public function __construct(EntityTypeManagerInterface $entity_type_manager) {
Chris@18 37 $this->entityTypeManager = $entity_type_manager;
Chris@0 38 }
Chris@0 39
Chris@0 40 /**
Chris@0 41 * {@inheritdoc}
Chris@0 42 */
Chris@0 43 public function enhance(array $defaults, Request $request) {
Chris@14 44 if (!$this->applies($defaults[RouteObjectInterface::ROUTE_OBJECT])) {
Chris@14 45 return $defaults;
Chris@14 46 }
Chris@18 47 if (($bundle = $this->entityTypeManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType()) && isset($defaults[$bundle])) {
Chris@0 48 // Field UI forms only need the actual name of the bundle they're dealing
Chris@0 49 // with, not an upcasted entity object, so provide a simple way for them
Chris@0 50 // to get it.
Chris@0 51 $defaults['bundle'] = $defaults['_raw_variables']->get($bundle);
Chris@0 52 }
Chris@0 53
Chris@0 54 return $defaults;
Chris@0 55 }
Chris@0 56
Chris@0 57 /**
Chris@0 58 * {@inheritdoc}
Chris@0 59 */
Chris@14 60 protected function applies(Route $route) {
Chris@0 61 return ($route->hasOption('_field_ui'));
Chris@0 62 }
Chris@0 63
Chris@0 64 }