Provides an Ajax link used with different HTTP methods.

Return value

array The AJAX link.

1 string reference to 'AjaxTestController::httpMethods'
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 429

Class

AjaxTestController
Provides content for dialog tests.

Namespace

Drupal\ajax_test\Controller

Code

public function httpMethods() : array {
  return [
    '#type' => 'link',
    '#title' => 'Link',
    '#url' => Url::fromRoute('ajax_test.http_methods.dialog'),
    '#attributes' => [
      'class' => [
        'use-ajax',
      ],
      'data-dialog-type' => 'modal',
      'data-dialog-options' => Json::encode([
        'width' => 800,
      ]),
      // Use this state var to change the HTTP method in tests.
      // @see \Drupal\FunctionalJavascriptTests\Ajax\DialogTest::testHttpMethod()
      'data-ajax-http-method' => \Drupal::state()
        ->get('ajax_test.http_method', 'POST'),
    ],
    '#attached' => [
      'library' => [
        'core/drupal.dialog.ajax',
      ],
    ],
  ];
}