Step 3/5 of #3642269: [meta] Migrate Ajax command attachments to the Render API.

Currently postponed on #3642278: [PP-1] Introduce CommandWithAttachmentsInterface and CommandWithAttachmentsTrait and migrate AnnounceCommand.

Problem/Motivation

Drupal doesn't have just one API for attaching libraries and JavaScript settings to an AjaxResponse. Apart from the widely adopted one in the Render API, we're maintaining a second one specific to Ajax commands.

#3642278: [PP-1] Introduce CommandWithAttachmentsInterface and CommandWithAttachmentsTrait and migrate AnnounceCommand makes AnnounceCommand's handler library a configurable default.

Two other core commands use getAttachedAssets() for exactly the same purpose. MessageCommand declares core/drupal.message, and TabledragWarningCommand declares core/drupal.tabledrag.ajax. Each call returns a fresh object containing that one library. Callers therefore cannot add to or replace the command's attachments as they can with AnnounceCommand.

Proposed resolution

  1. Have MessageCommand and TabledragWarningCommand implement CommandWithAttachmentsInterface and use CommandWithAttachmentsTrait. Each command declares its existing handler library as its default. Callers can extend its attachments with addAttachments() or replace them with setAttachments().
  2. Preserve existing subclass overrides of getAttachedAssets(), as for AnnounceCommand. Caller additions extend the assets supplied by the override. An explicit replacement takes precedence.
  3. Once all three commands support the Render API's attachment methods, deprecate getAttachedAssets() on those three commands. Keep the getter callable during the deprecation period. The shared Ajax interface and trait are still used by commands that render content.

API changes

MessageCommand and TabledragWarningCommand now support getAttachments(), addAttachments() and setAttachments().

Their getAttachedAssets() methods and AnnounceCommand::getAttachedAssets() are deprecated.

Data model changes

None.

Release notes snippet

Callers can now add to or replace the default attachments of MessageCommand and TabledragWarningCommand before adding them to an Ajax response.

Issue fork drupal-3642279

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pancho created an issue.