X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fmodules%2Fajax_test%2Fsrc%2FController%2FAjaxTestController.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fmodules%2Fajax_test%2Fsrc%2FController%2FAjaxTestController.php;h=1897719f6153d728d445c1d4cf98d9b69ffb7765;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=5ba65e8013a66ed372158617e17430f1ba7f8ffc;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website
diff --git a/web/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php b/web/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php
index 5ba65e801..1897719f6 100644
--- a/web/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php
+++ b/web/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php
@@ -42,6 +42,101 @@ class AjaxTestController {
return $content;
}
+ /**
+ * Example content for testing the wrapper of the response.
+ *
+ * @param string $type
+ * Type of response.
+ *
+ * @return array
+ * Renderable array of AJAX response contents.
+ */
+ public function renderTypes($type) {
+ return [
+ '#title' => 'AJAX Dialog & contents',
+ 'content' => [
+ '#type' => 'inline_template',
+ '#template' => $this->getRenderTypes()[$type]['render'],
+ ],
+ ];
+ }
+
+ /**
+ * Returns a render array of links that directly Drupal.ajax().
+ *
+ * @return array
+ * Renderable array of AJAX response contents.
+ */
+ public function insertLinksBlockWrapper() {
+ $methods = [
+ 'html',
+ 'replaceWith',
+ ];
+
+ $build['links'] = [
+ 'ajax_target' => [
+ '#markup' => '
',
+ ],
+ 'links' => [
+ '#theme' => 'links',
+ '#attached' => ['library' => ['ajax_test/ajax_insert']],
+ ],
+ ];
+ foreach ($methods as $method) {
+ foreach ($this->getRenderTypes() as $type => $item) {
+ $class = 'ajax-insert';
+ $build['links']['links']['#links']["$method-$type"] = [
+ 'title' => "Link $method $type",
+ 'url' => Url::fromRoute('ajax_test.ajax_render_types', ['type' => $type]),
+ 'attributes' => [
+ 'class' => [$class],
+ 'data-method' => $method,
+ 'data-effect' => $item['effect'],
+ ],
+ ];
+ }
+ }
+ return $build;
+ }
+
+ /**
+ * Returns a render array of links that directly Drupal.ajax().
+ *
+ * @return array
+ * Renderable array of AJAX response contents.
+ */
+ public function insertLinksInlineWrapper() {
+ $methods = [
+ 'html',
+ 'replaceWith',
+ ];
+
+ $build['links'] = [
+ 'ajax_target' => [
+ '#markup' => 'Target inline
',
+ ],
+ 'links' => [
+ '#theme' => 'links',
+ '#attached' => ['library' => ['ajax_test/ajax_insert']],
+ ],
+ ];
+ foreach ($methods as $method) {
+ foreach ($this->getRenderTypes() as $type => $item) {
+ $class = 'ajax-insert-inline';
+ $build['links']['links']['#links']["$method-$type"] = [
+ 'title' => "Link $method $type",
+ 'url' => Url::fromRoute('ajax_test.ajax_render_types', ['type' => $type]),
+ 'attributes' => [
+ 'class' => [$class],
+ 'data-method' => $method,
+ 'data-effect' => $item['effect'],
+ ],
+ ];
+ }
+ }
+ return $build;
+ }
+
/**
* Returns a render array that will be rendered by AjaxRenderer.
*
@@ -139,7 +234,7 @@ class AjaxTestController {
'data-dialog-type' => 'modal',
'data-dialog-options' => json_encode([
'width' => 400,
- ])
+ ]),
],
],
'link3' => [
@@ -151,7 +246,7 @@ class AjaxTestController {
'data-dialog-options' => json_encode([
'target' => 'ajax-test-dialog-wrapper-1',
'width' => 800,
- ])
+ ]),
],
],
'link4' => [
@@ -179,7 +274,7 @@ class AjaxTestController {
'data-dialog-options' => json_encode([
'width' => 800,
'height' => 500,
- ])
+ ]),
],
],
'link7' => [
@@ -190,7 +285,7 @@ class AjaxTestController {
'data-dialog-type' => 'dialog',
'data-dialog-options' => json_encode([
'width' => 800,
- ])
+ ]),
],
],
'link8' => [
@@ -222,4 +317,41 @@ class AjaxTestController {
return $response;
}
+ /**
+ * Render types.
+ *
+ * @return array
+ * Render types.
+ */
+ protected function getRenderTypes() {
+ $render_single_root = [
+ 'pre-wrapped-div' => 'pre-wrapped
',
+ 'pre-wrapped-span' => 'pre-wrapped',
+ 'pre-wrapped-whitespace' => ' pre-wrapped-whitespace
' . "\r\n",
+ 'not-wrapped' => 'not-wrapped',
+ 'comment-string-not-wrapped' => 'comment-string-not-wrapped',
+ 'comment-not-wrapped' => '',
+ 'svg' => '',
+ 'empty' => '',
+ ];
+ $render_multiple_root = [
+ 'mixed' => ' foo foo bar additional not wrapped strings, final string
',
+ 'top-level-only' => 'element #1
element #2
',
+ 'top-level-only-pre-whitespace' => ' element #1
element #2
',
+ 'top-level-only-middle-whitespace-span' => 'element #1 element #2',
+ 'top-level-only-middle-whitespace-div' => 'element #1
element #2
',
+ ];
+
+ $render_info = [];
+ foreach ($render_single_root as $key => $render) {
+ $render_info[$key] = ['render' => $render, 'effect' => 'fade'];
+ }
+ foreach ($render_multiple_root as $key => $render) {
+ $render_info[$key] = ['render' => $render, 'effect' => 'none'];
+ $render_info["$key--effect"] = ['render' => $render, 'effect' => 'fade'];
+ }
+
+ return $render_info;
+ }
+
}