- Issue created by @joachim
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.
- 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
Active
11.0 π₯
Last updated