function HtmxRequestInfoTrait::getHtmxTriggerName

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Htmx/HtmxRequestInfoTrait.php \Drupal\Core\Htmx\HtmxRequestInfoTrait::getHtmxTriggerName()

Extracts the trigger name from the HX-Source header.

Return value

string The value of the name attribute from the triggering element if present.

See also

core/assets/vendor/htmx/htmx.js:Htmx.#buildIdentifier

3 calls to HtmxRequestInfoTrait::getHtmxTriggerName()
ConfigSingleExportForm::buildForm in core/modules/config/src/Form/ConfigSingleExportForm.php
Form constructor.
HtmxRequestInfoTest::testGetHtmxTriggerName in core/tests/Drupal/Tests/Core/Htmx/HtmxRequestInfoTest.php
Tests the getHtmxTriggerName method.
HtmxTestForm::buildForm in core/modules/system/tests/modules/test_htmx/src/Form/HtmxTestForm.php
Form constructor.

File

core/lib/Drupal/Core/Htmx/HtmxRequestInfoTrait.php, line 118

Class

HtmxRequestInfoTrait
Provides methods for getting information about the HTMX request.

Namespace

Drupal\Core\Htmx

Code

protected function getHtmxTriggerName() : string {
  $value = $this->getHtmxSource();
  // Match any characters passed as name value.
  preg_match('#name="([\\s\\S]+)"#', $value, $matches);
  // $matches[1] contains the name string or an empty string.
  // encodeURI passes through the + character, so use rawurldecode().
  return rawurldecode($matches[1] ?? '');
}

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