class ContentControllerEnhancer

Enhances a route to select a controller based on the mime type of the request.

Hierarchy

Expanded class hierarchy of ContentControllerEnhancer

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

File

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

Namespace

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

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

  /**
   * Associative array of supported mime types and their appropriate controller.
   *
   * @var array
   */
  protected $types = array(
    'drupal_dialog' => 'controller.dialog:dialog',
    'drupal_modal' => 'controller.dialog:modal',
    'html' => 'controller.page:content',
  );

  /**
   * Constructs a new ContentControllerEnhancer 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['_controller']) && !empty($defaults['_content'])) {
      $type = $this->negotiation
        ->getContentType($request);
      if (isset($this->types[$type])) {
        $defaults['_controller'] = $this->types[$type];
      }
    }
    return $defaults;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentControllerEnhancer::$negotiation protected property Content negotiation library.
ContentControllerEnhancer::$types protected property Associative array of supported mime types and their appropriate controller.
ContentControllerEnhancer::enhance public function Update the defaults based on its own data and the request. Overrides RouteEnhancerInterface::enhance
ContentControllerEnhancer::__construct public function Constructs a new ContentControllerEnhancer object.