function HtmxTestAttachmentsController::generateHtmxButton

Static helper to for reusable render array.

Return value

array The render array.

1 call to HtmxTestAttachmentsController::generateHtmxButton()
HtmxTestAttachmentsController::page in core/modules/system/tests/modules/test_htmx/src/Controller/HtmxTestAttachmentsController.php
Builds the response.

File

core/modules/system/tests/modules/test_htmx/src/Controller/HtmxTestAttachmentsController.php, line 52

Class

HtmxTestAttachmentsController
Returns responses for HTMX Test Attachments routes.

Namespace

Drupal\test_htmx\Controller

Code

public static function generateHtmxButton() : array {
  $url = Url::fromRoute('test_htmx.attachments.replace');
  $build['replace'] = [
    '#type' => 'html_tag',
    '#tag' => 'button',
    '#attributes' => [
      'type' => 'button',
      'name' => 'replace',
      'data-hx-get' => $url->toString(),
      'data-hx-select' => 'div.ajax-content',
      'data-hx-target' => '[data-drupal-htmx-target]',
    ],
    '#value' => 'Click this',
    '#attached' => [
      'library' => [
        'core/drupal.htmx',
      ],
    ],
  ];
  $build['content'] = [
    '#type' => 'container',
    '#attributes' => [
      'data-drupal-htmx-target' => TRUE,
      'class' => [
        'htmx-test-container',
      ],
    ],
  ];
  return $build;
}

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