class EntityBundleRouteEnhancer

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Enhancer/EntityBundleRouteEnhancer.php \Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer
  2. 10 core/lib/Drupal/Core/Entity/Enhancer/EntityBundleRouteEnhancer.php \Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer

Sets the bundle parameter for routes with the _field_ui option.

Hierarchy

Expanded class hierarchy of EntityBundleRouteEnhancer

File

core/lib/Drupal/Core/Entity/Enhancer/EntityBundleRouteEnhancer.php, line 14

Namespace

Drupal\Core\Entity\Enhancer
View source
class EntityBundleRouteEnhancer implements EnhancerInterface {
    
    /**
     * The entity type manager service.
     *
     * @var \Drupal\Core\Entity\EntityTypeManagerInterface
     */
    protected $entityTypeManager;
    
    /**
     * Constructs a EntityBundleRouteEnhancer 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

Title Sort descending Modifiers Object type Summary Overriden Title
EntityBundleRouteEnhancer::$entityTypeManager protected property The entity type manager service.
EntityBundleRouteEnhancer::applies protected function
EntityBundleRouteEnhancer::enhance public function Updates the defaults for a route definition based on the request. Overrides EnhancerInterface::enhance
EntityBundleRouteEnhancer::__construct public function Constructs a EntityBundleRouteEnhancer object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.