function HtmxRequestInfoTrait::getHtmxSource
Retrieves the trigger identifier from an HTMX request header.
HTMX 4 uses encodeURI to safely encode multilingual attribute identifiers for HX-Source. We follow that convention but use the name attribute or the data-drupal-selector value when available rather than id.
Values will be a CSS selector constructed from the first available property:
- button[name="first_item"]
- button[data-drupal-selector="first_item"]
- button#id-value
- button
Return value
string The value of the 'HX-Source' header, or an empty string if not set.
See also
core/assets/vendor/htmx/htmx.js:Htmx.#createCoreHeaders
core/misc/htmx/htmx-assets.js:htmx_config_request()
3 calls to HtmxRequestInfoTrait::getHtmxSource()
- FormBuilder::prepareForm in core/
lib/ Drupal/ Core/ Form/ FormBuilder.php - Prepares a structured form array.
- HtmxRequestInfoTest::testGetHtmxSource in core/
tests/ Drupal/ Tests/ Core/ Htmx/ HtmxRequestInfoTest.php - Tests the getHtmxTrigger method.
- HtmxRequestInfoTrait::getHtmxTriggerName in core/
lib/ Drupal/ Core/ Htmx/ HtmxRequestInfoTrait.php - Extracts the trigger name from the HX-Source header.
File
-
core/
lib/ Drupal/ Core/ Htmx/ HtmxRequestInfoTrait.php, line 106
Class
- HtmxRequestInfoTrait
- Provides methods for getting information about the HTMX request.
Namespace
Drupal\Core\HtmxCode
protected function getHtmxSource() : string {
return rawurldecode($this->getRequest()->headers
->get('HX-Source', ''));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.