You are here

class FieldUiRouteEnhancer in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php \Drupal\field_ui\Routing\FieldUiRouteEnhancer

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

Hierarchy

Expanded class hierarchy of FieldUiRouteEnhancer

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

File

core/modules/field_ui/src/Routing/FieldUiRouteEnhancer.php, line 14

Namespace

Drupal\field_ui\Routing
View source
class FieldUiRouteEnhancer implements EnhancerInterface {

  /**
   * The entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a FieldUiRouteEnhancer object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function enhance(array $defaults, Request $request) {
    if (!$this
      ->applies($defaults[RouteObjectInterface::ROUTE_OBJECT])) {
      return $defaults;
    }
    if (($bundle = $this->entityTypeManager
      ->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}
   */
  protected function applies(Route $route) {
    return $route
      ->hasOption('_field_ui');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldUiRouteEnhancer::$entityTypeManager protected property The entity type manager service.
FieldUiRouteEnhancer::applies protected function
FieldUiRouteEnhancer::enhance public function Updates the defaults for a route definition based on the request. Overrides EnhancerInterface::enhance
FieldUiRouteEnhancer::__construct public function Constructs a FieldUiRouteEnhancer object.