Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

Why re-implement all time the same thing ? That what I said to me when I started to work with Ajax Callback and Ajax Commands.
So instead of re-implements for each case a new JS and solution to allow me to display some content generated by Ajax Command, I decided to make a generic solution.

To work with Ajax Command we need 3 things :

  • The JS which will request and execute the Ajax Command
  • The Controller which build the Ajax Response and what to do or display
  • The connector to link the JS to fields.

So the JS and the connector can be generic. The controller not because the role of a Controller is to do specific stuffs.

Features

This module provide you :

  • A generic JS which request and execute an Ajax Request.
  • A Formatter which alter the field type Link to allow us to plug the Ajax on a field.

How it works ?

The Formatter will slightly alter your field Link by :

  • Transforming the render element form link (a) to span (span).
  • Adding 2 new attributes to the render element :
    • data-execute-ajax-callback-field-formatter-url : Filled with the URL from the field link
    • data-execute-ajax-callback-field-formatter-id : Build with the following pattern "[entity_type]--[entity_id]-[field_name]--[delta]" with :
      • entity_type : The type of the entity containing the field
      • entity_id : The ID of the entity containing the field
      • field_name : The field name.
      • delta : The element's delta.

Thanks to attributes placed by the formatter the JS can be call and performs Ajax Request.

Post-Installation

Once the module installed, you should find a new Formatter for field type Link. You'll just have to use it.
To do it you have to set your field link following this rules :

  • In the URL you'll pass the url to your controller which response an Ajax Response.
  • In text part you'll set the default value

And you just have to create a new controller which return Ajax Response.

Supporting this Module

If you want to support this module, use it, share it and feel free to suggest improvements !

Activity

Total releases
2
First release
Feb 2025
Latest release
1 year ago
Release cadence
0 days
Stability
50% stable

Releases

Version Type Release date
1.1.0 Stable Feb 10, 2025
1.1.x-dev Dev Feb 10, 2025