diff --git a/core/core.services.yml b/core/core.services.yml index 106837a..250e387 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -268,13 +268,11 @@ services: arguments: ['@content_negotiation'] tags: - { name: route_enhancer, priority: 30 } - - { name: legacy_route_enhancer, priority: 30 } route_enhancer.modal: class: Drupal\Core\Routing\Enhancer\ModalEnhancer arguments: ['@content_negotiation'] tags: - { name: route_enhancer, priority: 20 } - - { name: legacy_route_enhancer, priority: 20 } route_enhancer.form: class: Drupal\Core\Routing\Enhancer\FormEnhancer arguments: ['@content_negotiation'] diff --git a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php index ac48bc8..d55cc94 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php @@ -19,9 +19,48 @@ /** * Main subscriber for VIEW HTTP responses. * - * @todo This needs to get refactored to be extensible so that we can handle - * more than just Html and Drupal-specific JSON requests. See - * http://drupal.org/node/1594870 + * Although it appears as though this class only handles a fixed list of + * content-types, it should be noted that this subscriber is only required when + * a controller does not return a Response object. If you have a requirement to + * handler another content-type there are two recommended approaches as follows + * + * Approach 1: + * a) Implement a service tagged with event_subscriber that implements + * \Symfony\Component\EventDispatcher\EventSubscriberInterface and reacts to + * \Symfony\Component\HttpKernel\KernelEvents::REQUEST and use that to register + * your content type. See \Drupal\Core\Ajax\AjaxSubscriber for an example. + * b) Create a service that implements + * \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface and is + * tagged as a 'route_enhancer'. If your service needs to react to legacy + * (hook_menu() page callbacks) it should also be tagged as + * 'legacy_route_enhancer'. In your service, use the + * RouterEnhancerInterface::enhance() method to examine the incoming request + * and routing defaults and nominate an appropriate controller. See + * \Drupal\Core\Routing\Enhancer\AjaxEnhancer for an example. + * c) Return an instance or sub-class of + * \Symfony\Component\HttpFoundation\Response from your controller. See + * \Drupal\Core\AjaxController for an example. + * + * Approach 2: + * a) Implement a service tagged with event_subscriber that implements + * \Symfony\Component\EventDispatcher\EventSubscriberInterface and reacts to + * \Symfony\Component\HttpKernel\KernelEvents::VIEW with a priority higher + * than this class. In your event listener, create a new Resonse object and + * set it as the event response using the setReponse() method on + * Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent. + * + * With one of these approaches, this class can be extended as required. + * + * @see \Drupal\Core\Ajax\AjaxSubscriber::onKernelRequest() + * @see \Drupal\Core\Routing\Enhancer\AjaxEnhancer::enhance() + * @see \Drupal\Core\AjaxController::content() + * @see \Symfony\Component\HttpFoundation\Response + * @see \Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface + * @see hook_menu() + * @see \Symfony\Component\HttpKernel\KernelEvents::REQUEST + * @see \Symfony\Component\HttpKernel\KernelEvents::VIEW + * @see Symfony\Component\EventDispatcher\EventSubscriberInterface + * @see Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent */ class ViewSubscriber implements EventSubscriberInterface { diff --git a/core/lib/Drupal/Core/Routing/Enhancer/DialogEnhancer.php b/core/lib/Drupal/Core/Routing/Enhancer/DialogEnhancer.php index 32bf977..0210de3 100644 --- a/core/lib/Drupal/Core/Routing/Enhancer/DialogEnhancer.php +++ b/core/lib/Drupal/Core/Routing/Enhancer/DialogEnhancer.php @@ -52,10 +52,7 @@ public function __construct(ContentNegotiation $negotiation) { */ public function enhance(array $defaults, Request $request) { if ($this->negotiation->getContentType($request) == $this->targetContentType) { - if (empty($defaults['_content']) && !empty($defaults['_controller'])) { - // Pass the controller on as content. - $defaults['_content'] = $defaults['_controller']; - } + $defaults['_content'] = $defaults['_controller']; $defaults['_controller'] = $this->controller; } return $defaults; diff --git a/core/modules/system/tests/modules/ajax_test/ajax_test.module b/core/modules/system/tests/modules/ajax_test/ajax_test.module index 5421f16..2522c15 100644 --- a/core/modules/system/tests/modules/ajax_test/ajax_test.module +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.module @@ -40,11 +40,6 @@ function ajax_test_menu() { 'page callback' => 'ajax_test_dialog', 'access callback' => TRUE, ); - $items['ajax-test/dialog-contents'] = array( - 'title' => 'AJAX Dialog contents', - 'page callback' => 'ajax_test_dialog_contents', - 'access callback' => TRUE, - ); $items['ajax-test/dialog-close'] = array( 'title' => 'AJAX Dialog close', 'page callback' => 'ajax_test_dialog_close', @@ -242,7 +237,7 @@ function _ajax_test_dialog($is_modal = FALSE) { } /** - * Menu callback: Returns the contents for dialogs opened by ajax_test_dialog(). + * Utlity function: Returns the contents for dialog tests. */ function ajax_test_dialog_contents() { // This is a regular render array; the keys do not have special meaning. diff --git a/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml b/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml new file mode 100644 index 0000000..6153f95 --- /dev/null +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml @@ -0,0 +1,6 @@ +ajax_test_dialog_contents: + pattern: ajax-test/dialog-contents + defaults: + _controller: '\Drupal\ajax_test\AjaxTestController::dialogContents' + requirements: + _access: 'TRUE' diff --git a/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/AjaxTestController.php b/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/AjaxTestController.php new file mode 100644 index 0000000..c8ba8c4 --- /dev/null +++ b/core/modules/system/tests/modules/ajax_test/lib/Drupal/ajax_test/AjaxTestController.php @@ -0,0 +1,21 @@ +