Prevent messages from other modules not being replaced
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3468931. --> Reported by: [abarrio](https://www.drupal.org/user/3349962) Related to !81 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Messenger service messages from other modules are being replaced when sending them using InsertCommand and method prepend on other modules.<br> On this code from frontend_editing.module method prepend is changed to replaceWith</p> <div class="codeblock"> <pre><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br></span><span style="color: #FF8000">/**<br>&nbsp;* Implements hook_ajax_render_alter().<br>&nbsp;*/<br></span><span style="color: #007700">function </span><span style="color: #0000BB">frontend_editing_ajax_render_alter</span><span style="color: #007700">(array &amp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">) {<br>&nbsp; foreach (</span><span style="color: #0000BB">$data </span><span style="color: #007700">as &amp;</span><span style="color: #0000BB">$command</span><span style="color: #007700">) {<br>&nbsp;&nbsp;&nbsp; if (</span><span style="color: #0000BB">$command</span><span style="color: #007700">[</span><span style="color: #DD0000">'command'</span><span style="color: #007700">] == </span><span style="color: #DD0000">'insert' </span><span style="color: #007700">&amp;&amp; </span><span style="color: #0000BB">$command</span><span style="color: #007700">[</span><span style="color: #DD0000">'method'</span><span style="color: #007700">] == </span><span style="color: #DD0000">'prepend'</span><span style="color: #007700">) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (</span><span style="color: #0000BB">strpos</span><span style="color: #007700">((string) </span><span style="color: #0000BB">$command</span><span style="color: #007700">[</span><span style="color: #DD0000">'data'</span><span style="color: #007700">], </span><span style="color: #DD0000">'data-drupal-messages'</span><span style="color: #007700">)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$command</span><span style="color: #007700">[</span><span style="color: #DD0000">'selector'</span><span style="color: #007700">] = </span><span style="color: #DD0000">'[data-drupal-messages], [data-drupal-messages-fallback]'</span><span style="color: #007700">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: #0000BB">$command</span><span style="color: #007700">[</span><span style="color: #DD0000">'method'</span><span style="color: #007700">] = </span><span style="color: #DD0000">'replaceWith'</span><span style="color: #007700">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br>}<br></span><span style="color: #0000BB">?&gt;</span></span></pre></div> <p>Everytime a module send a messenger using insert command is replaced for the last one.</p> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <ul> <li>Install together fronted_editing and content_lock.</li> <li>Create a page and edit it on two tabs to block it.</li> <li>Provoke an error on form validation</li> <li>You will see how lock message is replacing validation error.</li> </ul> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Check the path of ajax to see if it is from frontend_editing.</p>
issue