Enhances a route to select a controller based on the mime type of the request.
Expanded class hierarchy of ContentControllerEnhancer
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;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentControllerEnhancer:: |
protected | property | Content negotiation library. | |
ContentControllerEnhancer:: |
protected | property | Associative array of supported mime types and their appropriate controller. | |
ContentControllerEnhancer:: |
public | function |
Update the defaults based on its own data and the request. Overrides RouteEnhancerInterface:: |
|
ContentControllerEnhancer:: |
public | function | Constructs a new ContentControllerEnhancer object. |