From ad871286d1927097b8fc542e89cff90edaace8ef Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 13 May 2015 18:12:54 -0700 Subject: [PATCH] Issue #2472323 by dawehner, neclimdul, Crell, kim.pepper, nod_, Wim Leers, larowlan, jibran, pwolanin, catch: Move modal / dialog to query parameters --- core/core.services.yml | 9 +- core/lib/Drupal/Core/ContentNegotiation.php | 3 +- .../EventSubscriber/AcceptNegotiation406.php | 50 ++++++++++ .../ExceptionJsonSubscriber.php | 11 +++ .../MainContentViewSubscriber.php | 33 ++++--- .../Core/EventSubscriber/ViewSubscriber.php | 92 ------------------- .../Core/Render/Element/RenderElement.php | 2 +- core/misc/ajax.js | 23 ++++- core/modules/block/src/BlockListBuilder.php | 2 +- core/modules/ckeditor/js/ckeditor.js | 3 +- core/modules/config/src/Form/ConfigSync.php | 2 +- core/modules/hal/hal.services.yml | 4 + .../ExceptionHalJsonSubscriber.php | 24 +++++ .../rest/src/Routing/ResourceRoutes.php | 2 +- core/modules/rest/src/Tests/ReadTest.php | 8 +- core/modules/rest/src/Tests/ResourceTest.php | 2 +- core/modules/simpletest/src/WebTestBase.php | 43 +++++++-- .../system/src/Tests/Ajax/DialogTest.php | 13 +-- .../src/Controller/AjaxTestController.php | 13 +-- .../Tests/Core/ContentNegotiationTest.php | 3 - 20 files changed, 190 insertions(+), 152 deletions(-) create mode 100644 core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php delete mode 100644 core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php create mode 100644 core/modules/hal/src/EventSubscriber/ExceptionHalJsonSubscriber.php diff --git a/core/core.services.yml b/core/core.services.yml index 9139f904d35..c6161ab2a63 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -850,6 +850,10 @@ services: arguments: ['@class_resolver', '@current_route_match', '%main_content_renderers%'] tags: - { name: event_subscriber } + accept_negotiation_406: + class: Drupal\Core\EventSubscriber\AcceptNegotiation406 + tags: + - { name: event_subscriber } main_content_renderer.html: class: Drupal\Core\Render\MainContent\HtmlRenderer arguments: ['@title_resolver', '@plugin.manager.display_variant', '@event_dispatcher', '@element_info', '@module_handler', '@renderer', '@render_cache', '@cache_contexts_manager'] @@ -882,11 +886,6 @@ services: tags: - { name: event_subscriber } arguments: ['@router', '@router.request_context', NULL, '@request_stack'] - view_subscriber: - class: Drupal\Core\EventSubscriber\ViewSubscriber - arguments: ['@title_resolver'] - tags: - - { name: event_subscriber } bare_html_page_renderer: class: Drupal\Core\Render\BareHtmlPageRenderer arguments: ['@renderer'] diff --git a/core/lib/Drupal/Core/ContentNegotiation.php b/core/lib/Drupal/Core/ContentNegotiation.php index 857f9d59f64..e45c92dccdd 100644 --- a/core/lib/Drupal/Core/ContentNegotiation.php +++ b/core/lib/Drupal/Core/ContentNegotiation.php @@ -38,10 +38,9 @@ class ContentNegotiation { // Check all formats, if priority format is found return it. $first_found_format = FALSE; - $priority = array('html', 'drupal_ajax', 'drupal_modal', 'drupal_dialog'); foreach ($request->getAcceptableContentTypes() as $mime_type) { $format = $request->getFormat($mime_type); - if (in_array($format, $priority, TRUE)) { + if ($format === 'html') { return $format; } if (!is_null($format) && !$first_found_format) { diff --git a/core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php b/core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php new file mode 100644 index 00000000000..468ab9f919c --- /dev/null +++ b/core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php @@ -0,0 +1,50 @@ +getRequest(); + $result = $event->getControllerResult(); + + // If this is a render array then we assume that the router went with the + // generic controller and not one with a format. If the format requested is + // not HTML though we can also assume that the requested format is invalid + // so we provide a 406 response. + if (is_array($result) && $request->getRequestFormat() !== 'html') { + throw new NotAcceptableHttpException('Not acceptable'); + } + } + + /** + * {@inheritdoc} + */ + static function getSubscribedEvents() { + $events[KernelEvents::VIEW][] = ['onViewDetect406', -10]; + + return $events; + } + +} diff --git a/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php index 9610e8d6322..0aefe961c37 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php @@ -65,4 +65,15 @@ class ExceptionJsonSubscriber extends HttpExceptionSubscriberBase { $event->setResponse($response); } + /** + * Handles a 406 error for JSON. + * + * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event + * The event to process. + */ + public function on406(GetResponseForExceptionEvent $event) { + $response = new JsonResponse(['message' => $event->getException()->getMessage()], Response::HTTP_NOT_ACCEPTABLE); + $event->setResponse($response); + } + } diff --git a/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php index fcc51a3f802..07dce6efc4c 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php @@ -10,8 +10,6 @@ namespace Drupal\Core\EventSubscriber; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Routing\RouteMatchInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -50,6 +48,14 @@ class MainContentViewSubscriber implements EventSubscriberInterface { */ protected $mainContentRenderers; + /** + * URL query attribute to indicate the wrapper used to render a request. + * + * The wrapper format determines how the HTML is wrapped, for example in a + * modal dialog. + */ + const WRAPPER_FORMAT = '_wrapper_format'; + /** * Constructs a new MainContentViewSubscriber object. * @@ -76,22 +82,15 @@ class MainContentViewSubscriber implements EventSubscriberInterface { $request = $event->getRequest(); $result = $event->getControllerResult(); - $format = $request->getRequestFormat(); - // Render the controller result into a response if it's a render array. - if (is_array($result)) { - if (isset($this->mainContentRenderers[$format])) { - $renderer = $this->classResolver->getInstanceFromDefinition($this->mainContentRenderers[$format]); - $event->setResponse($renderer->renderResponse($result, $request, $this->routeMatch)); - } - else { - $supported_formats = array_keys($this->mainContentRenderers); - $supported_mimetypes = array_map([$request, 'getMimeType'], $supported_formats); - $event->setResponse(new JsonResponse([ - 'message' => 'Not Acceptable.', - 'supported_mime_types' => $supported_mimetypes, - ], 406)); - } + if (is_array($result) && ($request->query->has(static::WRAPPER_FORMAT) || $request->getRequestFormat() == 'html')) { + $wrapper = $request->query->get(static::WRAPPER_FORMAT, 'html'); + + // Fall back to HTML if the requested wrapper envelope is not available. + $wrapper = isset($this->mainContentRenderers[$wrapper]) ? $wrapper : 'html'; + + $renderer = $this->classResolver->getInstanceFromDefinition($this->mainContentRenderers[$wrapper]); + $event->setResponse($renderer->renderResponse($result, $request, $this->routeMatch)); } } diff --git a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php deleted file mode 100644 index 3485f1928be..00000000000 --- a/core/lib/Drupal/Core/EventSubscriber/ViewSubscriber.php +++ /dev/null @@ -1,92 +0,0 @@ -titleResolver = $title_resolver; - } - - /** - * Processes a successful controller into an HTTP 200 response. - * - * Some controllers may not return a response object but simply the body of - * one. The VIEW event is called in that case, to allow us to mutate that - * body into a Response object. In particular we assume that the return - * from an JSON-type response is a JSON string, so just wrap it into a - * Response object. - * - * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event - * The Event to process. - */ - public function onView(GetResponseForControllerResultEvent $event) { - $request = $event->getRequest(); - - if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { - $method = 'on' . $request->getRequestFormat(); - - if (method_exists($this, $method)) { - $event->setResponse($this->$method($event)); - } - else { - $event->setResponse(new Response('Not Acceptable', 406)); - } - } - } - - public function onJson(GetResponseForControllerResultEvent $event) { - $page_callback_result = $event->getControllerResult(); - - $response = new JsonResponse(); - $response->setData($page_callback_result); - - return $response; - } - - /** - * Registers the methods in this class that should be listeners. - * - * @return array - * An array of event listener definitions. - */ - static function getSubscribedEvents() { - $events[KernelEvents::VIEW][] = array('onView'); - - return $events; - } -} diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index 0283333b1cd..87b9f022236 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -240,7 +240,7 @@ abstract class RenderElement extends PluginBase implements ElementInterface { $settings += array( 'url' => isset($settings['callback']) ? Url::fromRoute('system.ajax') : NULL, 'options' => array(), - 'accepts' => 'application/vnd.drupal-ajax' + 'dialogType' => 'ajax', ); // @todo Legacy support. Remove in Drupal 8. diff --git a/core/misc/ajax.js b/core/misc/ajax.js index e2aeab15caf..d80c2c5a896 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -52,7 +52,7 @@ element_settings.url = $(this).attr('href'); element_settings.event = 'click'; } - element_settings.accepts = $(this).data('accepts'); + element_settings.dialogType = $(this).data('dialog-type'); element_settings.dialog = $(this).data('dialog-options'); var baseUseAjax = $(this).attr('id'); Drupal.ajax[baseUseAjax] = new Drupal.ajax(baseUseAjax, this, element_settings); @@ -256,9 +256,6 @@ } }, dataType: 'json', - accepts: { - json: element_settings.accepts || 'application/vnd.drupal-ajax' - }, type: 'POST' }; @@ -266,6 +263,16 @@ ajax.options.data.dialogOptions = element_settings.dialog; } + // Ensure that we have a valid URL by adding ? when no query parameter is + // yet available, otherwise append using &. + if (ajax.options.url.indexOf('?') === -1) { + ajax.options.url += '?'; + } + else { + ajax.options.url += '&'; + } + ajax.options.url += Drupal.ajax.WRAPPER_FORMAT + '=drupal_' + (element_settings.dialogType || 'ajax'); + // Bind the ajaxSubmit function to the element event. $(ajax.element).on(element_settings.event, function (event) { return ajax.eventResponse(this, event); @@ -288,6 +295,14 @@ } }; + /** + * URL query attribute to indicate the wrapper used to render a request. + * + * The wrapper format determines how the HTML is wrapped, for example in a + * modal dialog. + */ + Drupal.ajax.WRAPPER_FORMAT = '_wrapper_format'; + /** * Handle a key press. * diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php index 652128758ca..913b7184c0b 100644 --- a/core/modules/block/src/BlockListBuilder.php +++ b/core/modules/block/src/BlockListBuilder.php @@ -362,7 +362,7 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface ]), 'attributes' => array( 'class' => array('use-ajax', 'block-filter-text-source'), - 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-type' => 'modal', 'data-dialog-options' => Json::encode(array( 'width' => 700, )), diff --git a/core/modules/ckeditor/js/ckeditor.js b/core/modules/ckeditor/js/ckeditor.js index 15968085bb7..3df3366a3ce 100644 --- a/core/modules/ckeditor/js/ckeditor.js +++ b/core/modules/ckeditor/js/ckeditor.js @@ -160,9 +160,10 @@ // a Drupal.ajax instance to load the dialog and trigger it. var $content = $('
' + Drupal.t('Loading...') + '
'); $content.appendTo($target); + new Drupal.ajax('ckeditor-dialog', $content.find('a').get(0), { - accepts: 'application/vnd.drupal-modal', dialog: dialogSettings, + dialogType: 'modal', selector: '.ckeditor-dialog-loading-link', url: url, event: 'ckeditor-internal.ckeditor', diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php index b97218b03b3..0a917587788 100644 --- a/core/modules/config/src/Form/ConfigSync.php +++ b/core/modules/config/src/Form/ConfigSync.php @@ -281,7 +281,7 @@ class ConfigSync extends FormBase { 'url' => Url::fromRoute($route_name, $route_options), 'attributes' => array( 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-type' => 'modal', 'data-dialog-options' => json_encode(array( 'width' => 700 )), diff --git a/core/modules/hal/hal.services.yml b/core/modules/hal/hal.services.yml index 7e40df0d5b8..e817fbf34b7 100644 --- a/core/modules/hal/hal.services.yml +++ b/core/modules/hal/hal.services.yml @@ -26,3 +26,7 @@ services: class: Drupal\hal\Encoder\JsonEncoder tags: - { name: encoder, priority: 10, format: hal_json } + exception.default_json: + class: Drupal\hal\EventSubscriber\ExceptionHalJsonSubscriber + tags: + - { name: event_subscriber } diff --git a/core/modules/hal/src/EventSubscriber/ExceptionHalJsonSubscriber.php b/core/modules/hal/src/EventSubscriber/ExceptionHalJsonSubscriber.php new file mode 100644 index 00000000000..765e8457d80 --- /dev/null +++ b/core/modules/hal/src/EventSubscriber/ExceptionHalJsonSubscriber.php @@ -0,0 +1,24 @@ +httpRequest($entity_type . '/9999', 'GET', NULL, $this->defaultMimeType); $this->assertResponse(404); $path = $entity_type == 'node' ? '/node/{node}' : '/entity_test/{entity_test}'; - $expected_message = Json::encode(['error' => 'A fatal error occurred: The "' . $entity_type . '" parameter was not converted for the path "' . $path . '" (route name: "rest.entity.' . $entity_type . '.GET.hal_json")']); + $expected_message = Json::encode(['message' => 'The "' . $entity_type . '" parameter was not converted for the path "' . $path . '" (route name: "rest.entity.' . $entity_type . '.GET.hal_json")']); $this->assertIdentical($expected_message, $response, 'Response message is correct.'); // Make sure that field level access works and that the according field is @@ -81,7 +81,7 @@ class ReadTest extends RESTTestBase { $this->drupalLogout(); $response = $this->httpRequest($entity->urlInfo(), 'GET', NULL, $this->defaultMimeType); $this->assertResponse(403); - $this->assertIdentical('{}', $response); + $this->assertIdentical('{"message":""}', $response); } // Try to read a resource which is not REST API enabled. $account = $this->drupalCreateUser(); @@ -92,7 +92,9 @@ class ReadTest extends RESTTestBase { // and hence when there is no matching REST route, the non-REST route is // used, but it can't render into application/hal+json, so it returns a 406. $this->assertResponse('406', 'HTTP response code is 406 when the resource does not define formats, because it falls back to the canonical, non-REST route.'); - $this->assertTrue(strpos($response, '{"message":"Not Acceptable.","supported_mime_types":') !== FALSE); + $this->assertEqual($response, Json::encode([ + 'message' => 'Not acceptable', + ])); } /** diff --git a/core/modules/rest/src/Tests/ResourceTest.php b/core/modules/rest/src/Tests/ResourceTest.php index be0261712a4..5144ae325a0 100644 --- a/core/modules/rest/src/Tests/ResourceTest.php +++ b/core/modules/rest/src/Tests/ResourceTest.php @@ -54,7 +54,7 @@ class ResourceTest extends RESTTestBase { $this->config->save(); $this->rebuildCache(); - // Verify that accessing the resource returns 401. + // Verify that accessing the resource returns 406. $response = $this->httpRequest($this->entity->urlInfo(), 'GET', NULL, $this->defaultMimeType); // AcceptHeaderMatcher considers the canonical, non-REST route a match, but // a lower quality one: no format restrictions means there's always a match, diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 50f95331db1..99cb227e6c6 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -13,11 +13,13 @@ use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Yaml; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\SafeMarkup; +use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Cache\Cache; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Core\Render\Element; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AnonymousUserSession; @@ -1421,8 +1423,8 @@ abstract class WebTestBase extends TestBase { * Requests a Drupal path in drupal_ajax format and JSON-decodes the response. */ protected function drupalGetAjax($path, array $options = array(), array $headers = array()) { - if (!preg_grep('/^Accept:/', $headers)) { - $headers[] = 'Accept: application/vnd.drupal-ajax'; + if (!isset($options['query'][MainContentViewSubscriber::WRAPPER_FORMAT])) { + $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax'; } return Json::decode($this->drupalGet($path, $options, $headers)); } @@ -1650,17 +1652,24 @@ abstract class WebTestBase extends TestBase { * @see ajax.js */ protected function drupalPostAjaxForm($path, $edit, $triggering_element, $ajax_path = NULL, array $options = array(), array $headers = array(), $form_html_id = NULL, $ajax_settings = NULL) { + // Get the content of the initial page prior to calling drupalPostForm(), // since drupalPostForm() replaces $this->content. if (isset($path)) { - $this->drupalGet($path, $options); + // Avoid sending the wrapper query argument to drupalGet so we can fetch + // the form and populate the internal WebTest values. + $get_options = $options; + unset($get_options['query'][MainContentViewSubscriber::WRAPPER_FORMAT]); + $this->drupalGet($path, $get_options); } $content = $this->content; $drupal_settings = $this->drupalSettings; - if (!preg_grep('/^Accept:/', $headers)) { - $headers[] = 'Accept: application/vnd.drupal-ajax'; - } + // Provide a default value for the wrapper envelope. + $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = + isset($options['query'][MainContentViewSubscriber::WRAPPER_FORMAT]) ? + $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] : + 'drupal_ajax'; // Get the Ajax settings bound to the triggering element. if (!isset($ajax_settings)) { @@ -1699,8 +1708,26 @@ abstract class WebTestBase extends TestBase { // Unless a particular path is specified, use the one specified by the // Ajax settings, or else 'system/ajax'. if (!isset($ajax_path)) { - $ajax_path = isset($ajax_settings['url']) ? $ajax_settings['url'] : 'system/ajax'; + if (isset($ajax_settings['url'])) { + // In order to allow to set for example the wrapper envelope query + // parameter we need to get the system path again. + $parsed_url = UrlHelper::parse($ajax_settings['url']); + $options['query'] = $parsed_url['query'] + $options['query']; + $options += ['fragment' => $parsed_url['fragment']]; + + // We know that $parsed_url['path'] is already with the base path + // attached. + $ajax_path = preg_replace( + '/^' . preg_quote(base_path(), '/') . '/', + '', + $parsed_url['path'] + ); + } + else { + $ajax_path = 'system/ajax'; + } } + $ajax_path = $this->container->get('unrouted_url_assembler')->assemble('base://' . $ajax_path, $options); // Submit the POST request. $return = Json::decode($this->drupalPostForm(NULL, $edit, array('path' => $ajax_path, 'triggering_element' => $triggering_element), $options, $headers, $form_html_id, $extra_post)); diff --git a/core/modules/system/src/Tests/Ajax/DialogTest.php b/core/modules/system/src/Tests/Ajax/DialogTest.php index 482e025eb50..e290977be18 100644 --- a/core/modules/system/src/Tests/Ajax/DialogTest.php +++ b/core/modules/system/src/Tests/Ajax/DialogTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Ajax; +use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Core\Url; /** @@ -93,7 +94,7 @@ class DialogTest extends AjaxTestBase { $this->assertRaw($dialog_contents, 'Non-JS modal dialog page present.'); // Emulate going to the JS version of the page and check the JSON response. - $ajax_result = $this->drupalGetAjax('ajax-test/dialog-contents', array(), array('Accept: application/vnd.drupal-modal')); + $ajax_result = $this->drupalGetAjax('ajax-test/dialog-contents', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal'))); $this->assertEqual($modal_expected_response, $ajax_result[3], 'Modal dialog JSON response matches.'); // Check that requesting a "normal" dialog without JS goes to a page. @@ -106,7 +107,7 @@ class DialogTest extends AjaxTestBase { $ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', array( // We have to mock a form element to make drupalPost submit from a link. 'textfield' => 'test', - ), array(), 'ajax-test/dialog-contents', array(), array('Accept: application/vnd.drupal-dialog'), NULL, array( + ), array(), 'ajax-test/dialog-contents', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog')), array(), NULL, array( 'submit' => array( 'dialogOptions[target]' => 'ajax-test-dialog-wrapper-1', ) @@ -119,7 +120,7 @@ class DialogTest extends AjaxTestBase { $ajax_result = $this->drupalPostAjaxForm('ajax-test/dialog', array( // We have to mock a form element to make drupalPost submit from a link. 'textfield' => 'test', - ), array(), 'ajax-test/dialog-contents', array(), array('Accept: application/vnd.drupal-dialog'), NULL, array( + ), array(), 'ajax-test/dialog-contents', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_dialog')), array(), NULL, array( // Don't send a target. 'submit' => array() )); @@ -159,13 +160,13 @@ class DialogTest extends AjaxTestBase { $this->assertTrue(!empty($form), 'Non-JS form page present.'); // Emulate going to the JS version of the form and check the JSON response. - $ajax_result = $this->drupalGetAjax('ajax-test/dialog-form', array(), array('Accept: application/vnd.drupal-modal')); + $ajax_result = $this->drupalGetAjax('ajax-test/dialog-form', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal'))); $expected_ajax_settings = [ 'edit-preview' => [ 'callback' => '::preview', 'event' => 'click', 'url' => Url::fromRoute('system.ajax')->toString(), - 'accepts' => 'application/vnd.drupal-ajax', + 'dialogType' => 'ajax', 'submit' => [ '_triggering_element_name' => 'op', '_triggering_element_value' => 'Preview', @@ -188,7 +189,7 @@ class DialogTest extends AjaxTestBase { $this->assertTrue(!empty($form), 'Non-JS entity form page present.'); // Emulate going to the JS version of the form and check the JSON response. - $ajax_result = $this->drupalGetAjax('admin/structure/contact/add', array(), array('Accept: application/vnd.drupal-modal')); + $ajax_result = $this->drupalGetAjax('admin/structure/contact/add', array('query' => array(MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_modal'))); $this->setRawContent($ajax_result[3]['data']); // Remove the data, the form build id and token will never match. unset($ajax_result[3]['data']); diff --git a/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php b/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php index b54b823b89d..ff4859de572 100644 --- a/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php +++ b/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php @@ -120,7 +120,7 @@ class AjaxTestController { '#url' => Url::fromRoute('ajax_test.dialog_contents'), '#attributes' => array( 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-type' => 'modal', ), ); @@ -133,7 +133,7 @@ class AjaxTestController { 'url' => Url::fromRoute('ajax_test.dialog_contents'), 'attributes' => array( 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-type' => 'modal', 'data-dialog-options' => json_encode(array( 'width' => 400, )) @@ -144,7 +144,7 @@ class AjaxTestController { 'url' => Url::fromRoute('ajax_test.dialog_contents'), 'attributes' => array( 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-dialog', + 'data-dialog-type' => 'dialog', 'data-dialog-options' => json_encode(array( 'target' => 'ajax-test-dialog-wrapper-1', 'width' => 800, @@ -156,6 +156,7 @@ class AjaxTestController { 'url' => Url::fromRoute('ajax_test.dialog_close'), 'attributes' => array( 'class' => array('use-ajax'), + 'data-dialog-type' => 'modal', ), ), 'link5' => array( @@ -163,7 +164,7 @@ class AjaxTestController { 'url' => Url::fromRoute('ajax_test.dialog_form'), 'attributes' => array( 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-type' => 'modal', ), ), 'link6' => array( @@ -171,7 +172,7 @@ class AjaxTestController { 'url' => Url::fromRoute('contact.form_add'), 'attributes' => array( 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-type' => 'modal', 'data-dialog-options' => json_encode(array( 'width' => 800, 'height' => 500, @@ -183,7 +184,7 @@ class AjaxTestController { 'url' => Url::fromRoute('ajax_test.dialog_contents'), 'attributes' => array( 'class' => array('use-ajax'), - 'data-accepts' => 'application/vnd.drupal-dialog', + 'data-dialog-type' => 'dialog', 'data-dialog-options' => json_encode(array( 'width' => 800, )) diff --git a/core/tests/Drupal/Tests/Core/ContentNegotiationTest.php b/core/tests/Drupal/Tests/Core/ContentNegotiationTest.php index e4110084c85..d5f3081a974 100644 --- a/core/tests/Drupal/Tests/Core/ContentNegotiationTest.php +++ b/core/tests/Drupal/Tests/Core/ContentNegotiationTest.php @@ -60,9 +60,6 @@ class ContentNegotiationTest extends UnitTestCase { public function priorityFormatProvider() { return [ - ['drupal_dialog', ['format' => 'drupal_dialog', 'mime_type' => 'application/vnd.drupal-dialog']], - ['drupal_modal', ['format' => 'drupal_modal', 'mime_type' => 'application/vnd.drupal-modal']], - ['drupal_ajax', ['format' => 'drupal_ajax', 'mime_type' => 'application/vnd.drupal-ajax']], ['html', ['format' => 'html', 'mime_type' => 'text/html']], ]; }