+ /**
+ * 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' => '<em>AJAX Dialog & contents</em>',
+ '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' => '<div class="ajax-target-wrapper"><div id="ajax-target">Target</div></div>',
+ ],
+ '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' => '<div class="ajax-target-wrapper"><span id="ajax-target-inline">Target inline</span></div>',
+ ],
+ '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;
+ }
+