Problem/Motivation

CommandWithAttachedAssetsInterface::getAttachedAssets() documents NULL as a valid return value.

After adding the rendered command, AjaxResponse::addCommand() however assumes the getter returned an object and unconditionally calls getLibraries() on it.

Background

The bug was introduced in 2015 with #2347469: Rendering forms in AjaxResponses does not attach assets automatically.

@samuel.mortenson's patch in #2663316-52: Broken title in modal dialog when title is a render array already handled this case while addressing a dialog title bug. When #101 dropped the proposed support for attachments on dialog titles, it also dropped the fix in AjaxResponse::addCommand().

Steps to reproduce

From a custom Ajax command's implementation of CommandWithAttachedAssetsInterface::getAttachedAssets(), return NULL and add the command to an AjaxResponse.

The call fails with Call to a member function getLibraries() on null.

Proposed resolution

Skip merging assets when the getter returns NULL.

Add a regression test that verifies the response contains the rendered command and retains its existing attachments.

Remaining tasks

Review.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

n/a

Issue fork drupal-3642232

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. See original summary.

pancho’s picture

Status: Active » Needs review

Ready for review.

When committing, please add @samuel.mortenson to the credits.