diff --git a/core/lib/Drupal/Core/FormatMapping.php b/core/lib/Drupal/Core/FormatMapping.php index 3b3166c..40e6aea 100644 --- a/core/lib/Drupal/Core/FormatMapping.php +++ b/core/lib/Drupal/Core/FormatMapping.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\Core\FormatMapping. + * Contains \Drupal\Core\FormatMapping. */ namespace Drupal\Core; @@ -36,7 +36,7 @@ public function getContentType(Request $request) { return 'iframeupload'; } - if ($type = $request->query->get('dataType')) { + if ($type = $request->query->get('dialogType')) { return 'drupal_' . $type; } diff --git a/core/lib/Drupal/Core/Render/Element/RenderElement.php b/core/lib/Drupal/Core/Render/Element/RenderElement.php index ba47f97..87b9f02 100644 --- a/core/lib/Drupal/Core/Render/Element/RenderElement.php +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php @@ -240,6 +240,7 @@ public static function preRenderAjaxForm($element) { $settings += array( 'url' => isset($settings['callback']) ? Url::fromRoute('system.ajax') : NULL, 'options' => array(), + 'dialogType' => 'ajax', ); // @todo Legacy support. Remove in Drupal 8. diff --git a/core/misc/ajax.js b/core/misc/ajax.js index c788c16..9bd28f1 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -255,7 +255,7 @@ ajax.options.data.dialogOptions = element_settings.dialog; } if (element_settings.dialogType) { - ajax.options.url += '?dataType=' + element_settings.dialogType; + ajax.options.url += '?dialogType=' + element_settings.dialogType; } // Bind the ajaxSubmit function to the element event. diff --git a/core/modules/system/src/Tests/Ajax/DialogTest.php b/core/modules/system/src/Tests/Ajax/DialogTest.php index 482e025..28a3d0c 100644 --- a/core/modules/system/src/Tests/Ajax/DialogTest.php +++ b/core/modules/system/src/Tests/Ajax/DialogTest.php @@ -165,7 +165,7 @@ public function testDialog() { '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', diff --git a/core/tests/Drupal/Tests/Core/FormatMappingTest.php b/core/tests/Drupal/Tests/Core/FormatMappingTest.php index 36921e8..f24e09b 100644 --- a/core/tests/Drupal/Tests/Core/FormatMappingTest.php +++ b/core/tests/Drupal/Tests/Core/FormatMappingTest.php @@ -15,12 +15,12 @@ * @coversDefaultClass \Drupal\Core\FormatMapping * @group FormatMapping */ -class ContentNegotiationTest extends UnitTestCase { +class FormatMappingTest extends UnitTestCase { /** * @var \Drupal\Core\FormatMapping */ - protected $contentNegotiation; + protected $formatMapping; /** * {@inheritdoc} @@ -28,7 +28,7 @@ class ContentNegotiationTest extends UnitTestCase { protected function setUp() { parent::setUp(); - $this->contentNegotiation = new FormatMapping; + $this->formatMapping = new FormatMapping; } /** @@ -40,7 +40,7 @@ public function testAjaxIframeUpload() { $request = new Request(); $request->attributes->set('ajax_iframe_upload', '1'); - $this->assertSame('iframeupload', $this->contentNegotiation->getContentType($request)); + $this->assertSame('iframeupload', $this->formatMapping->getContentType($request)); } /** @@ -51,19 +51,21 @@ public function testAjaxIframeUpload() { */ public function testAPriorityFormatIsFound($priority, $format) { $request = new Request(); - $request->setFormat($format['format'], $format['mime_type']); - $request->headers->set('Accept', sprintf('%s,application/json', $format['mime_type'])); - $this->assertSame($priority, $this->contentNegotiation->getContentType($request)); + if ($format) { + $request->query->set('dialogType', $format); + } + + $this->assertSame($priority, $this->formatMapping->getContentType($request)); } 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']], + ['drupal_dialog', 'dialog'], + ['drupal_modal', 'modal'], + ['drupal_ajax', 'ajax'], + ['html', ''], ]; } @@ -76,7 +78,7 @@ public function testNoPriorityFormatIsFoundButReturnsTheFirstValidOne() { $request = new Request(); $request->headers->set('Accept', 'application/rdf+xml'); - $this->assertSame('rdf', $this->contentNegotiation->getContentType($request)); + $this->assertSame('rdf', $this->formatMapping->getContentType($request)); } /** @@ -87,7 +89,7 @@ public function testNoPriorityFormatIsFoundButReturnsTheFirstValidOne() { public function testUnknowContentTypeReturnsHtmlByDefault() { $request = new Request(); - $this->assertSame('html', $this->contentNegotiation->getContentType($request)); + $this->assertSame('html', $this->formatMapping->getContentType($request)); } /** @@ -99,7 +101,7 @@ public function testUnknowContentTypeButAjaxRequest() { $request = new Request(); $request->headers->set('X-Requested-With', 'XMLHttpRequest'); - $this->assertSame('ajax', $this->contentNegotiation->getContentType($request)); + $this->assertSame('ajax', $this->formatMapping->getContentType($request)); } }