function Htmx::createJsonAttribute
Utility method to create and store an array as an attribute.
Parameters
string $id: The HTMX attribute id.
array{string, string} $value: The attribute values.
3 calls to Htmx::createJsonAttribute()
- Htmx::headers in core/
lib/ Drupal/ Core/ Htmx/ Htmx.php - Creates a `data-hx-headers` attribute.
- Htmx::request in core/
lib/ Drupal/ Core/ Htmx/ Htmx.php - Creates a `data-hx-request` attribute.
- Htmx::vals in core/
lib/ Drupal/ Core/ Htmx/ Htmx.php - Creates a `data-hx-vals` attribute.
File
-
core/
lib/ Drupal/ Core/ Htmx/ Htmx.php, line 183
Class
- Htmx
- Presents the HTMX controls for developers to use with render arrays.
Namespace
Drupal\Core\HtmxCode
protected function createJsonAttribute(string $id, array $value) : void {
$key = self::ATTRIBUTE_PREFIX . $id;
// Ensure the object format HTMX shows in documentation.
// Ensure numeric strings are encoded as numbers.
$json = json_encode($value, JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK);
$this->attributes[$key] = new AttributeString($key, $json);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.