class AjaxEnhancer

Enhances an ajax route with the appropriate controller.

Hierarchy

Expanded class hierarchy of AjaxEnhancer

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

File

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

Namespace

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

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

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

  /**
   * {@inheritdoc}
   */
  public function enhance(array $defaults, Request $request) {
    if (empty($defaults['_content']) && $this->negotiation
      ->getContentType($request) == 'drupal_ajax') {
      $defaults['_content'] = isset($defaults['_controller']) ? $defaults['_controller'] : NULL;
      $defaults['_controller'] = '\\Drupal\\Core\\Controller\\AjaxController::content';
    }
    return $defaults;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AjaxEnhancer::$negotiation protected property Content negotiation library.
AjaxEnhancer::enhance public function Update the defaults based on its own data and the request. Overrides RouteEnhancerInterface::enhance
AjaxEnhancer::__construct public function Constructs a new \Drupal\Core\Routing\Enhancer\AjaxEnhancer object.