By fathershawn on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
11.3.x
Introduced in version:
11.3.0
Issue links:
Description:
HTMX passes information about the context of the request in a set of custom headers. This information is useful to developers building dynamic responses.
The trait Drupal\Core\Htmx\HtmxRequestInfoTrait is included in Drupal 11.3 and has been added to Drupal\Core\Form\FormBase. This trait can be added to a controller or any other class building render arrays for HTMX.
HtmxRequestInfoTrait includes an abstract method which must be implemented on the exhibiting class:
/**
* Gets the request object.
*
* @return \Symfony\Component\HttpFoundation\Request
* The request object.
*/
abstract protected function getRequest();
Before
$trigger = $this->getRequest()->headers->get('HX-Trigger-Name');
if ($trigger === 'config_type') {
…
}
elseif ($trigger === 'config_name') {
…
}
After
if ($this->getHtmxTriggerName() === 'config_type') {
…
}
elseif ($this->getHtmxTriggerName() === 'config_name') {
…
}
Impacts:
Module developers
Site templates, recipes and distribution developers