class HtmxFragmentController
Returns responses for HTMX Test Fixtures routes.
Attributes
#[Route(name: 'test_htmx.', requirements: [
'_permission' => 'access content',
], defaults: [
'_title' => 'Htmx Fragment',
])]
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\AutowireTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\test_htmx\Controller\HtmxFragmentController extends \Drupal\Core\Controller\ControllerBase
Expanded class hierarchy of HtmxFragmentController
File
-
core/
modules/ system/ tests/ modules/ test_htmx/ src/ Controller/ HtmxFragmentController.php, line 13
Namespace
Drupal\test_htmx\ControllerView source
final class HtmxFragmentController extends ControllerBase {
/**
* Builds the partial response.
*/
public function buildPartial(string $target, string $swap) : array {
return [
'#type' => 'inline_template',
'#template' => <<<HTMX_PARTIAL
<hx-partial hx-target="{{ target }}" hx-swap="{{ swap }}">
{{item}}
</hx-partial>
HTMX_PARTIAL,
'#context' => [
'target' => $target,
'swap' => $swap,
'item' => $swap === 'delete' ? '' : [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => 'Inserted by htmx!',
],
],
];
}
public function buildDeleteInsertPartial() : array {
return [
'missing' => $this->buildPartial('div.does-not-exist', 'outerHTML'),
'insert' => $this->buildPartial('[data-drupal-wrapper-selector="edit-partial-replace"]', 'outerHTML'),
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.