Update documentation in CommandWithAttachedAssetsInterface to clarify that it can be used with commands that don't return render arrays

Created on 5 February 2019, almost 6 years ago
Updated 31 January 2023, almost 2 years ago

Problem/Motivation

Follow up to #3020352: Create a new AnnounceCommand to call Drupal.announce on an AjaxResponse β†’

In that issue we use CommandWithAttachedAssetsInterface because we needed to attach the core/drupal.announce library.

This works well because \Drupal\Core\Ajax\AjaxResponse::addCommand()
will call \Drupal\Core\Ajax\CommandWithAttachedAssetsInterface::getAttachedAssets()
for any $command that implements the interface.

The documentation though on this interface says

* Interface for Ajax commands that render content and attach assets.
*
* All Ajax commands that render HTML should implement these methods
* to be able to return attached assets to the calling AjaxResponse object.
*

The interface itself has nothing to do with rendering content. Just commands that need to attach libraries.

Furthermore "render content" is ambiguous here. Does the new AnnounceCommand do this? It calls Drupal.announce which does cause html to be update on the page similarly to \Drupal\Core\Ajax\InsertCommand which also implements this interface and calls ultimately the jQuery insert method.

I think what was probably meant instead of "render content" was probably "returns a render array"

We can see this with the Trait CommandWithAttachedAssetsTrait. This trait sets attached assets based on $this->content being a render array. Before #3020352: Create a new AnnounceCommand to call Drupal.announce on an AjaxResponse β†’ all classes that implemented CommandWithAttachedAssetsInterface also used CommandWithAttachedAssetsTrait

Proposed resolution

Update the docs in CommandWithAttachedAssetsInterface to separate it out of it's use can in CommandWithAttachedAssetsTrait

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
AjaxΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024