You are here

class FieldUiRouteEnhancer in Scheduled Updates 8

Enhances Field UI routes by adding proper information about the bundle name.

Hierarchy

Expanded class hierarchy of FieldUiRouteEnhancer

1 string reference to 'FieldUiRouteEnhancer'
scheduled_updates.services.yml in ./scheduled_updates.services.yml
scheduled_updates.services.yml
1 service uses FieldUiRouteEnhancer
scheduled_updates.route_enhancer in ./scheduled_updates.services.yml
Drupal\scheduled_updates\Routing\FieldUiRouteEnhancer

File

src/Routing/FieldUiRouteEnhancer.php, line 19
Contains \Drupal\scheduled_updates\Routing\FieldUiRouteEnhancer.

Namespace

Drupal\scheduled_updates\Routing
View source
class FieldUiRouteEnhancer implements RouteEnhancerInterface {

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a FieldUiRouteEnhancer object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function enhance(array $defaults, Request $request) {
    if (!$this
      ->applies($defaults[RouteObjectInterface::ROUTE_OBJECT])) {
      return $defaults;
    }
    if (($bundle = $this->entityManager
      ->getDefinition($defaults['entity_type_id'])
      ->getBundleEntityType()) && isset($defaults[$bundle])) {

      // Field UI forms only need the actual name of the bundle they're dealing
      // with, not an upcasted entity object, so provide a simple way for them
      // to get it.
      $defaults['bundle'] = $defaults['_raw_variables']
        ->get($bundle);
    }
    return $defaults;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return $route
      ->hasOption('_scheduled_updates');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldUiRouteEnhancer::$entityManager protected property The entity manager.
FieldUiRouteEnhancer::applies public function Declares if the route enhancer applies to the given route. Overrides RouteEnhancerInterface::applies
FieldUiRouteEnhancer::enhance public function Update the defaults based on its own data and the request.
FieldUiRouteEnhancer::__construct public function Constructs a FieldUiRouteEnhancer object.