FormRouteEnhancer.php 980 B

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