class FormEnhancer

Enhances a form route with the appropriate controller.

Hierarchy

Expanded class hierarchy of FormEnhancer

1 string reference to 'FormEnhancer'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml

File

drupal/core/lib/Drupal/Core/Routing/Enhancer/FormEnhancer.php, line 17
Contains \Drupal\Core\Routing\Enhancer\FormEnhancer.

Namespace

Drupal\Core\Routing\Enhancer
View source
class FormEnhancer implements RouteEnhancerInterface {

  /**
   * Content negotiation library.
   *
   * @var \Drupal\CoreContentNegotiation
   */
  protected $negotiation;

  /**
   * Constructs a new \Drupal\Core\Routing\Enhancer\FormEnhancer object.
   *
   * @param \Drupal\Core\ContentNegotiation $negotiation
   *   The Content Negotiation service.
   */
  public function __construct(ContentNegotiation $negotiation) {
    $this->negotiation = $negotiation;
  }

  /**
   * {@inhertdoc}
   */
  public function enhance(array $defaults, Request $request) {
    if (empty($defaults['_controller']) && !empty($defaults['_form']) && $this->negotiation
      ->getContentType($request) === 'html') {
      $defaults['_controller'] = '\\Drupal\\Core\\Controller\\HtmlFormController::content';
    }
    return $defaults;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormEnhancer::$negotiation protected property Content negotiation library.
FormEnhancer::enhance public function {@inhertdoc} Overrides RouteEnhancerInterface::enhance
FormEnhancer::__construct public function Constructs a new \Drupal\Core\Routing\Enhancer\FormEnhancer object.