"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.9/core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php" (18 Nov 2020, 1859 Bytes) of package /linux/www/drupal-8.9.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "FieldUiRouteEnhancer.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.0.8_vs_9.1.0-rc1.

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