Mercurial > hg > isophonics-drupal-site
annotate 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 |
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\Enhancer\RouteEnhancerInterface; |
Chris@0 | 7 use Symfony\Component\HttpFoundation\Request; |
Chris@0 | 8 use Symfony\Component\Routing\Route; |
Chris@0 | 9 |
Chris@0 | 10 /** |
Chris@0 | 11 * Enhances Field UI routes by adding proper information about the bundle name. |
Chris@0 | 12 */ |
Chris@0 | 13 class FieldUiRouteEnhancer implements RouteEnhancerInterface { |
Chris@0 | 14 |
Chris@0 | 15 /** |
Chris@0 | 16 * The entity manager. |
Chris@0 | 17 * |
Chris@0 | 18 * @var \Drupal\Core\Entity\EntityManagerInterface |
Chris@0 | 19 */ |
Chris@0 | 20 protected $entityManager; |
Chris@0 | 21 |
Chris@0 | 22 /** |
Chris@0 | 23 * Constructs a FieldUiRouteEnhancer object. |
Chris@0 | 24 * |
Chris@0 | 25 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager |
Chris@0 | 26 * The entity manager. |
Chris@0 | 27 */ |
Chris@0 | 28 public function __construct(EntityManagerInterface $entity_manager) { |
Chris@0 | 29 $this->entityManager = $entity_manager; |
Chris@0 | 30 } |
Chris@0 | 31 |
Chris@0 | 32 /** |
Chris@0 | 33 * {@inheritdoc} |
Chris@0 | 34 */ |
Chris@0 | 35 public function enhance(array $defaults, Request $request) { |
Chris@0 | 36 if (($bundle = $this->entityManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType()) && isset($defaults[$bundle])) { |
Chris@0 | 37 // Field UI forms only need the actual name of the bundle they're dealing |
Chris@0 | 38 // with, not an upcasted entity object, so provide a simple way for them |
Chris@0 | 39 // to get it. |
Chris@0 | 40 $defaults['bundle'] = $defaults['_raw_variables']->get($bundle); |
Chris@0 | 41 } |
Chris@0 | 42 |
Chris@0 | 43 return $defaults; |
Chris@0 | 44 } |
Chris@0 | 45 |
Chris@0 | 46 /** |
Chris@0 | 47 * {@inheritdoc} |
Chris@0 | 48 */ |
Chris@0 | 49 public function applies(Route $route) { |
Chris@0 | 50 return ($route->hasOption('_field_ui')); |
Chris@0 | 51 } |
Chris@0 | 52 |
Chris@0 | 53 } |