function HtmxTestAttachmentsController::generateHtmxButton
Static helper to for reusable render array.
Return value
array The render array.
5 calls to HtmxTestAttachmentsController::generateHtmxButton()
- HtmxTestAttachmentsController::after in core/
modules/ system/ tests/ modules/ test_htmx/ src/ Controller/ HtmxTestAttachmentsController.php - Builds a response with an `afterend` swap.
- HtmxTestAttachmentsController::before in core/
modules/ system/ tests/ modules/ test_htmx/ src/ Controller/ HtmxTestAttachmentsController.php - Builds a response with a `beforebegin` swap.
- HtmxTestAttachmentsController::page in core/
modules/ system/ tests/ modules/ test_htmx/ src/ Controller/ HtmxTestAttachmentsController.php - Builds the response.
- HtmxTestAttachmentsController::replaceWithAjax in core/
modules/ system/ tests/ modules/ test_htmx/ src/ Controller/ HtmxTestAttachmentsController.php - We need a static callback that ignores callback parameters.
- HtmxTestAttachmentsController::withWrapperFormat in core/
modules/ system/ tests/ modules/ test_htmx/ src/ Controller/ HtmxTestAttachmentsController.php - Builds a response with an the wrapper format parameter on the request.
File
-
core/
modules/ system/ tests/ modules/ test_htmx/ src/ Controller/ HtmxTestAttachmentsController.php, line 94
Class
- HtmxTestAttachmentsController
- Returns responses for HTMX Test Attachments routes.
Namespace
Drupal\test_htmx\ControllerCode
public static function generateHtmxButton(string $swap = '', bool $useWrapperFormat = FALSE) : array {
$options = [];
if ($useWrapperFormat) {
$options = [
'query' => [
MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_htmx',
],
];
}
$url = Url::fromRoute('test_htmx.attachments.replace', [], $options);
$build['replace'] = [
'#type' => 'html_tag',
'#tag' => 'button',
'#attributes' => [
'type' => 'button',
'name' => 'replace',
],
'#value' => 'Click this',
];
$replace_htmx = (new Htmx())->get($url)
->select('div.ajax-content')
->target('[data-drupal-htmx-target]');
if ($swap !== '') {
$replace_htmx->swap($swap);
}
$replace_htmx->applyTo($build['replace']);
$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.