FormRouteEnhancer.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php
  2. 10 core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php
  3. 11.x core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php

Namespace

Drupal\Core\Routing\Enhancer

File

core/lib/Drupal/Core/Routing/Enhancer/FormRouteEnhancer.php

View source
<?php

namespace Drupal\Core\Routing\Enhancer;

use Drupal\Core\Routing\EnhancerInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;

/**
 * Enhancer to add a wrapping controller for _form routes.
 */
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;
    }

}

Classes

Title Deprecated Summary
FormRouteEnhancer Enhancer to add a wrapping controller for _form routes.

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