Problem/Motivation

I'm trying to send a status message using the core messenger service in Drupal 10. The message ends up being duplicated.

Its getting printed twice on the mercury editor page due to line 12 ({{ form['status_messages'] }}`) of /mercury_editor/templates/mercury-editor-entity-form.html.twig.

Separate issue but related to the the same form (first time I have seen this) the following is printed out in the twig on development

<!-- INVALID FILE NAME SUGGESTIONS: See https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/function/hook_theme_suggestions_alter
   mercury_editor_entity_form -->

Steps to reproduce

Don't judge as the following is just the start of my development for an assigned tasked and nowhere near complete.

I added the following to a hook_form_alter().

 $messenger = \Drupal::messenger();
      $state = $form["moderation_state"]['widget'][0]['state']['#default_value'];
      $messenger->addMessage(t('This content is currently @state.', ['@state' => $state]), MessengerInterface::TYPE_WARNING);

And the screenshot is what I see on my content node using Mercury Editor.
screenshot of mercury editor printing a status message twice

The top is the message printed from core and the bottom from mercury-editor-entity-form.html.twig.

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

pbabin created an issue. See original summary.

pbabin’s picture

Issue summary: View changes
pbabin’s picture

Issue summary: View changes
fizcs3’s picture

Version: 2.1.x-dev » 2.2.4
StatusFileSize
new48.31 KB

I'm seeing the same duplication of status messages; on mercury_editor 2.2.4.
In our case, we are using the contrib content_lock module, and it's message appears:
two status messages pic

What I'm finding is that the {{ form['status_messages'] }} (mentioned above, and below) is displaying the second smaller status message.

templates/mercury-editor-entity-form.html.twig

{{ attach_library('mercury_editor/node_form') }}
{{ form['status_messages'] }}
<header class="me-node-form__header">
  <h1 class="me-node-form__title">{{ form['#title'] }}</h1>
</header>
{{ form|without('status_messages', 'advanced', 'footer', 'actions', 'gin_actions', 'gin_sidebar', 'gin_sidebar_toggle') }}

It's the page template that displays the larger "system" status message at the top via {{ page.highlighted }}:

templates/page--mercury-editor.html.twig

<mercury-dialog id="me-edit-screen" hide-close-button push resizable dock="right">
  {{ page.highlighted }}
  {{ page.content|without(local_actions_block) }}
</mercury-dialog>

So, it depends which status message style is wanted here? I presume the second one is what we want, less space used.
If so, then the task instead would be to remove the status message that displays in the highlighted region...

anirudhsingh19’s picture

Assigned: Unassigned » anirudhsingh19

working on this.

anirudhsingh19’s picture

Assigned: anirudhsingh19 » Unassigned
Status: Active » Needs review

As mentioned by @fizcs3, The duplicate messages were caused by 2 templates.

templates/page--mercury-editor.html.twig

<mercury-dialog id="me-edit-screen" hide-close-button push resizable dock="right">
  {{ page.highlighted }} # Responsible code
  {{ page.content|without(local_actions_block) }}
</mercury-dialog>
templates/mercury-editor-entity-form.html.twig
{{ attach_library('mercury_editor/node_form') }}
{{ form['status_messages'] }} # Responsible code
<header class="me-node-form__header">
  <h1 class="me-node-form__title">{{ form['#title'] }}</h1>
</header>
{{ form|without('status_messages', 'advanced', 'footer', 'actions', 'gin_actions', 'gin_sidebar', 'gin_sidebar_toggle') }}

I think the later was better to be removed as the first one was styled better, according to the default administration theme.

jldust’s picture

Version: 2.2.4 » 3.0.x-dev
Status: Needs review » Fixed

With the recent error changes in the Form Error Validations issue this has been resolved and should be included in the next tagged release.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.