Mercurial > hg > cmmr2012-drupal-site
annotate core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | 12f9dff5fda9 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\field_ui\Routing; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Entity\EntityManagerInterface; |
Chris@0 | 6 use Drupal\Core\Routing\EnhancerInterface; |
Chris@0 | 7 use Symfony\Cmf\Component\Routing\RouteObjectInterface; |
Chris@0 | 8 use Symfony\Component\HttpFoundation\Request; |
Chris@0 | 9 use Symfony\Component\Routing\Route; |
Chris@0 | 10 |
Chris@0 | 11 /** |
Chris@0 | 12 * Enhances Field UI routes by adding proper information about the bundle name. |
Chris@0 | 13 */ |
Chris@0 | 14 class FieldUiRouteEnhancer implements EnhancerInterface { |
Chris@0 | 15 |
Chris@0 | 16 /** |
Chris@0 | 17 * The entity manager. |
Chris@0 | 18 * |
Chris@0 | 19 * @var \Drupal\Core\Entity\EntityManagerInterface |
Chris@0 | 20 */ |
Chris@0 | 21 protected $entityManager; |
Chris@0 | 22 |
Chris@0 | 23 /** |
Chris@0 | 24 * Constructs a FieldUiRouteEnhancer object. |
Chris@0 | 25 * |
Chris@0 | 26 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager |
Chris@0 | 27 * The entity manager. |
Chris@0 | 28 */ |
Chris@0 | 29 public function __construct(EntityManagerInterface $entity_manager) { |
Chris@0 | 30 $this->entityManager = $entity_manager; |
Chris@0 | 31 } |
Chris@0 | 32 |
Chris@0 | 33 /** |
Chris@0 | 34 * {@inheritdoc} |
Chris@0 | 35 */ |
Chris@0 | 36 public function enhance(array $defaults, Request $request) { |
Chris@0 | 37 if (!$this->applies($defaults[RouteObjectInterface::ROUTE_OBJECT])) { |
Chris@0 | 38 return $defaults; |
Chris@0 | 39 } |
Chris@0 | 40 |
Chris@0 | 41 if (($bundle = $this->entityManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType()) && isset($defaults[$bundle])) { |
Chris@0 | 42 // Field UI forms only need the actual name of the bundle they're dealing |
Chris@0 | 43 // with, not an upcasted entity object, so provide a simple way for them |
Chris@0 | 44 // to get it. |
Chris@0 | 45 $defaults['bundle'] = $defaults['_raw_variables']->get($bundle); |
Chris@0 | 46 } |
Chris@0 | 47 |
Chris@0 | 48 return $defaults; |
Chris@0 | 49 } |
Chris@0 | 50 |
Chris@0 | 51 /** |
Chris@0 | 52 * {@inheritdoc} |
Chris@0 | 53 */ |
Chris@0 | 54 protected function applies(Route $route) { |
Chris@0 | 55 return ($route->hasOption('_field_ui')); |
Chris@0 | 56 } |
Chris@0 | 57 |
Chris@0 | 58 } |