Prevent messages from other modules not being replaced

Created on 19 August 2024, 4 months ago
Updated 3 September 2024, 4 months ago

Problem/Motivation

Messenger service messages from other modules are being replaced when sending them using InsertCommand and method prepend on other modules.
On this code from frontend_editing.module method prepend is changed to replaceWith

/**
 * Implements hook_ajax_render_alter().
 */
function frontend_editing_ajax_render_alter(array &$data) {
  foreach ($data as &$command) {
    if ($command['command'] == 'insert' && $command['method'] == 'prepend') {
      if (strpos((string) $command['data'], 'data-drupal-messages')) {
        $command['selector'] = '[data-drupal-messages], [data-drupal-messages-fallback]';
        $command['method'] = 'replaceWith';
      }
    }
  }
}

Everytime a module send a messenger using insert command is replaced for the last one.

Steps to reproduce

  • Install together fronted_editing and content_lock.
  • Create a page and edit it on two tabs to block it.
  • Provoke an error on form validation
  • You will see how lock message is replacing validation error.

Proposed resolution

Check the path of ajax to see if it is from frontend_editing.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain abarrio

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024