You are here

public function AjaxTestController::insertLinksBlockWrapper in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php \Drupal\ajax_test\Controller\AjaxTestController::insertLinksBlockWrapper()

Returns a render array of links that directly Drupal.ajax().

Return value

array Renderable array of AJAX response contents.

1 string reference to 'AjaxTestController::insertLinksBlockWrapper'
ajax_test.routing.yml in core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml
core/modules/system/tests/modules/ajax_test/ajax_test.routing.yml

File

core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php, line 70

Class

AjaxTestController
Provides content for dialog tests.

Namespace

Drupal\ajax_test\Controller

Code

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;
}