Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Ajax Callback Field Formatter

No security coverage Drupal 9–11
View on drupal.org

This module provides a generic JavaScript solution and a field formatter to easily integrate AJAX callbacks and commands with Drupal fields. It allows you to create custom AJAX responses in your controllers and display them within your content by configuring a link field.

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 !

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Oct 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 3
Maintenance
Dormant

Release Timeline

Releases

Version Type Core Release date
1.1.0 Stable 9–11 Feb 10, 2025
1.1.x-dev Dev 9–11 Feb 10, 2025
1.0.0 Stable 9–11 Oct 28, 2024