annotate core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\field_ui\Routing;
Chris@0 4
Chris@5 5 use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
Chris@0 6 use Drupal\Core\Routing\EnhancerInterface;
Chris@0 7 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
Chris@5 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@0 15 class FieldUiRouteEnhancer implements EnhancerInterface {
Chris@5 16 use DeprecatedServicePropertyTrait;
Chris@0 17
Chris@0 18 /**
Chris@5 19 * {@inheritdoc}
Chris@5 20 */
Chris@5 21 protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
Chris@5 22
Chris@5 23 /**
Chris@5 24 * The entity type manager service.
Chris@0 25 *
Chris@5 26 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
Chris@0 27 */
Chris@5 28 protected $entityTypeManager;
Chris@0 29
Chris@0 30 /**
Chris@0 31 * Constructs a FieldUiRouteEnhancer object.
Chris@0 32 *
Chris@5 33 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
Chris@5 34 * The entity type manager service.
Chris@0 35 */
Chris@5 36 public function __construct(EntityTypeManagerInterface $entity_type_manager) {
Chris@5 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@0 44 if (!$this->applies($defaults[RouteObjectInterface::ROUTE_OBJECT])) {
Chris@0 45 return $defaults;
Chris@0 46 }
Chris@5 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@0 60 protected function applies(Route $route) {
Chris@0 61 return ($route->hasOption('_field_ui'));
Chris@0 62 }
Chris@0 63
Chris@0 64 }