function EntityBundleRouteEnhancer::enhance

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Entity/Enhancer/EntityBundleRouteEnhancer.php \Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer::enhance()
  2. 11.x core/lib/Drupal/Core/Entity/Enhancer/EntityBundleRouteEnhancer.php \Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer::enhance()

Overrides EnhancerInterface::enhance

File

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

Class

EntityBundleRouteEnhancer
Sets the bundle parameter for routes with the _field_ui option.

Namespace

Drupal\Core\Entity\Enhancer

Code

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;
}

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