function AjaxTestController::insertLinksBlockWrapper

Same name in other branches
  1. 9 core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php \Drupal\ajax_test\Controller\AjaxTestController::insertLinksBlockWrapper()
  2. 8.9.x core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php \Drupal\ajax_test\Controller\AjaxTestController::insertLinksBlockWrapper()
  3. 11.x 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 71

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.