
Here’s the full video!ECA is a Drupal module built for automating things you might otherwise need to create custom code modules to do. You create an ECA “model” with one or more Events, connect them to Actions, and optionally add Conditions to determine which actions to apply – ECA is short for “Events, Conditions and Actions.”The HTMX model uses the ECA HTMX integration. I created it as a custom field available to node content types, and it sends a rendered custom htmx element that contains the polling configuration. As a field, you can then place it on the content type’s manage display tab.A comment thread in Drupal works totally fine. You fill in a form, click submit, and your comment gets posted. Same way it has for over 20 years.
What is HTMX?
So things like replacing parts of the page in response to a click, or in this case, a timer, can be done with some relatively basic markup.But if somebody else replies when you’re on the page, you don’t see anything change, you don’t get any notification.
What is ECA?
We need two models – one for adding the HTMX element to the page, and the other to respond to the polling requests and deliver the current state of the comment field.
How do we add polling using ECA and HTMX?
The endpoint model defines a custom server route that the polling calls. This simply gets the node id from the parameter passed by the browser, and returns the rendered comment field. It also, as part of its process, triggers the Matrix polling provided by Matrix API — so when a visitor on the site’s browser polls the Drupal site for new comments, the Drupal site requests new messages from Matrix before responding.Now when we connect Matrix – a chat system – to Drupal – a comment system – we have a mismatch. How do we make it so you can see new comments as they come in?This may seem like a complete tangent — but this is something cool that’s now been slipped into Drupal 11, as a stable addition in Drupal 11.3.0. HTMX is a collection of HTML widgets with modern Javascript to handle a variety of things baked into them. By using HTMX, you don’t even need to write Javascript for a huge number of scenarios — you just add attributes to HTML elements that describes what you want to do, and HTMX handles the actual Javascript necessary.The simplest answer: Polling. Have some Javascript running in your browser that periodically checks for new messages on the server.





