remove the magic empty selector for InsertCommand

Created on 14 April 2024, 9 months ago

Problem/Motivation

The InsertCommand ajax command takes a CSS selector as a constructor parameter:

public function __construct($selector, $content, array $settings = NULL) {

However, AjaxRenderer, which is called when a form ajax submit callback returns a form array, does this:

    // The selector for the insert command is NULL as the new content will
    // replace the element making the Ajax call. The default 'replaceWith'
    // behavior can be changed with #ajax['method'].
    $response->addCommand(new InsertCommand(NULL, $html));

This is undocumented behaviour in the backend PHP code.

The handling of this magic is done in the FE JS code:

    insert(ajax, response) {
      // Get information from the response. If it is not there, default to
      // our presets.
      const $wrapper = response.selector
        ? $(response.selector)
        : $(ajax.wrapper);

Having this magic special case that's made up of code in two completely different areas, the FE and BE, doesn't seem like good DX or maintainability to me.

Steps to reproduce

Proposed resolution

- Deprecated the special behaviour in ajax.js
- Deprecate creating InsertCommand with a NULL selector
- Change the instances of the code in core that do this, so that they pass in a selector

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
AjaxΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

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

Comments & Activities

Production build 0.71.5 2024