Implement HtmxAttributes class

Created on 22 June 2024, 5 months ago
Updated 19 July 2024, 4 months ago

Problem/Motivation

Implement the HtmxAttribute class discussed in πŸ“Œ [POC] Implementing some components of the Ajax system using HTMX Active and in the process take care of 🌱 [policy, no patch] Choose a markup strategy for HTMX POC Fixed

Proposed resolution

Refined from #13 πŸ“Œ [POC] Implementing some components of the Ajax system using HTMX Active in the POC discussion:

HTMX expresses itself in HTML attributes. We extend \Drupal\Core\Template\Attribute to create an HtmxAttribute that has class methods for the various attributes used by HTMX? That would allow us to support something like this:


$someRenderArray = [
  '#attributes' => ['class' => ['foo']],
];

$htmx = new HtmxAttributes($someRenderArray['#attributes]);

$htmx->get(Url::fromRoute(
    route_name: 'htmx.htmx_entity_view',
    route_parameters: ['entityType' => 'node', 'entity' => 27, 'viewMode' => 'teaser'])->toString()
  )
  ->select('article')
  ->target('main')
  ->swap('beforeEnd');

$someRenderArray = [
  '#attributes' => $htmx->toArray(),
];

Each class method would call \Drupal\Core\Template\Attribute::createAttributeValue and create the correct attribute. Our process function callback for the render process then just needs to merge the HtmxAttribute object with any existing Attribute object and set the result as the element's Attribute.

Remaining tasks

Provide MR
Change Documentation on project page

User interface changes

-

API changes

All htmx attribute construction and formatting to be done in HtmxAttribute

Data model changes

-

πŸ“Œ Task
Status

Fixed

Version

1.2

Component

Drupal Code

Created by

πŸ‡©πŸ‡ͺGermany c-logemann Frankfurt/M, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024