diff --git a/core/modules/system/tests/modules/ajax_test/ajax_test.libraries.yml b/core/modules/system/tests/modules/ajax_test/ajax_test.libraries.yml index f1c7306..772a05f 100644 --- a/core/modules/system/tests/modules/ajax_test/ajax_test.libraries.yml +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.libraries.yml @@ -1,3 +1,8 @@ +ajax_insert: + js: + js/insert-ajax.js: {} + dependencies: + - core/drupal.ajax order: drupalSettings: ajax: test 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 index e8d06c0..89191a1 100644 --- a/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml +++ b/core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml @@ -6,6 +6,14 @@ ajax_test.dialog_contents: requirements: _access: 'TRUE' +ajax_test.ajax_render_types: + path: '/ajax-test/dialog-contents-types/{type}' + defaults: + _title: 'AJAX Dialog contents routing' + _controller: '\Drupal\ajax_test\Controller\AjaxTestController::renderTypes' + requirements: + _access: 'TRUE' + ajax_test.dialog_form: path: '/ajax-test/dialog-form' defaults: @@ -21,6 +29,13 @@ ajax_test.dialog: requirements: _access: 'TRUE' +ajax_test.insert_links: + path: '/ajax-test/insert' + defaults: + _controller: '\Drupal\ajax_test\Controller\AjaxTestController::insertLinks' + requirements: + _access: 'TRUE' + ajax_test.dialog_close: path: '/ajax-test/dialog-close' defaults: diff --git a/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js new file mode 100644 index 0000000..d4cde4d --- /dev/null +++ b/core/modules/system/tests/modules/ajax_test/js/insert-ajax.js @@ -0,0 +1,24 @@ +/** + * @file + * Provides method to test ajax requests. + */ + +(function ($, window, Drupal, drupalSettings) { + 'use strict'; + + Drupal.behaviors.insertTest = { + attach: function (context, settings) { + $('.ajax-insert').once('ajax-insert').on('click', function (event) { + event.preventDefault(); + var ajaxSettings = { + url: event.currentTarget.getAttribute('href'), + wrapper: 'ajax-target', + base: false, + element: false + }; + var myAjaxObject = Drupal.ajax(ajaxSettings); + myAjaxObject.execute(); + }); + } + }; +})(jQuery, window, Drupal, drupalSettings); 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 63cc0ab..a4e757c 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 @@ -43,6 +43,83 @@ public static function dialogContents() { } /** + * Example content for testing whether response should be wrapped in div. + * + * @param string $type + * Type of response. Either 'pre-wrapped', 'not-wrapped', 'mixed'. + * + * @return array + * Renderable array of AJAX response contents. + */ + public static function renderTypes($type) { + // This is a regular render array; the keys do not have special meaning. + switch ($type) { + case 'pre-wrapped': + $markup = '