function HtmxTestAttachmentsController::replace

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/modules/test_htmx/src/Controller/HtmxTestAttachmentsController.php \Drupal\test_htmx\Controller\HtmxTestAttachmentsController::replace()

Builds the HTMX response.

Return value

mixed[] A render array.

1 call to HtmxTestAttachmentsController::replace()
HtmxTestAttachmentsController::delete in core/modules/system/tests/modules/test_htmx/src/Controller/HtmxTestAttachmentsController.php
Set up a delete swap test.
1 string reference to 'HtmxTestAttachmentsController::replace'
test_htmx.routing.yml in core/modules/system/tests/modules/test_htmx/test_htmx.routing.yml
core/modules/system/tests/modules/test_htmx/test_htmx.routing.yml

File

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

Class

HtmxTestAttachmentsController
Returns responses for HTMX Test Attachments routes.

Namespace

Drupal\test_htmx\Controller

Code

public function replace() : array {
  $build['content'] = [
    '#type' => 'container',
    '#attached' => [
      'library' => [
        'test_htmx/assets',
      ],
    ],
    '#attributes' => [
      'class' => [
        'ajax-content',
      ],
    ],
    'example' => [
      '#markup' => 'Initial Content',
    ],
  ];
  $request = \Drupal::request();
  $format = $request->query
    ->get('_wrapper_format');
  if ($format === 'drupal_htmx') {
    // The query parameter was set.
    $build['content']['#attributes']['class'][] = 'htmx-test-flag';
  }
  return $build;
}

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