You are here

class FormRouteEnhancer in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php \Drupal\Core\Routing\Enhancer\FormRouteEnhancer

Enhancer to add a wrapping controller for _form routes.

Hierarchy

Expanded class hierarchy of FormRouteEnhancer

1 string reference to 'FormRouteEnhancer'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses FormRouteEnhancer
route_enhancer.form in core/core.services.yml
Drupal\Core\Routing\Enhancer\FormRouteEnhancer

File

core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php, line 13

Namespace

Drupal\Core\Routing\Enhancer
View source
class FormRouteEnhancer implements EnhancerInterface {

  /**
   * Returns whether the enhancer runs on the current route.
   *
   * @param \Drupal\Core\Routing\Enhancer\Route $route
   *   The current route.
   *
   * @return bool
   */
  protected function applies(Route $route) {
    return $route
      ->hasDefault('_form') && !$route
      ->hasDefault('_controller');
  }

  /**
   * {@inheritdoc}
   */
  public function enhance(array $defaults, Request $request) {
    $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
    if (!$this
      ->applies($route)) {
      return $defaults;
    }
    $defaults['_controller'] = 'controller.form:getContentResult';
    return $defaults;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormRouteEnhancer::applies protected function Returns whether the enhancer runs on the current route.
FormRouteEnhancer::enhance public function Updates the defaults for a route definition based on the request. Overrides EnhancerInterface::enhance