c812178d29248616a1c83416cd995aa6c6bb51bc
[yaffs-website] / web / core / lib / Drupal / Core / Routing / Enhancer / FormRouteEnhancer.php
1 <?php
2
3 namespace Drupal\Core\Routing\Enhancer;
4
5 use Drupal\Core\Routing\EnhancerInterface;
6 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\Routing\Route;
9
10 /**
11  * Enhancer to add a wrapping controller for _form routes.
12  */
13 class FormRouteEnhancer implements EnhancerInterface {
14
15   /**
16    * Returns whether the enhancer runs on the current route.
17    *
18    * @param \Drupal\Core\Routing\Enhancer\Route $route
19    *   The current route.
20    *
21    * @return bool
22    */
23   protected function applies(Route $route) {
24     return $route->hasDefault('_form') && !$route->hasDefault('_controller');
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function enhance(array $defaults, Request $request) {
31     $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
32     if (!$this->applies($route)) {
33       return $defaults;
34     }
35
36     $defaults['_controller'] = 'controller.form:getContentResult';
37     return $defaults;
38   }
39
40 }