Problem/Motivation

If a user flags or unflags content, Drupal displays a status message. If no "(un)flagged message" is set (which is possible, because it's not required in settings form), this status message is empty (box with no content).

Steps to reproduce:

  1. Go to flags settings: /admin/structure/flags
  2. Make sure "Flagged message" and/or "Unflagged message" is not set.
  3. Flag content

Proposed resolution

Don't show status message if text is empty.

Comments

pminf created an issue. See original summary.

pminf’s picture

StatusFileSize
new810 bytes

Patch to just check if message text is empty before adding it.

pminf’s picture

Status: Active » Needs review
pminf’s picture

StatusFileSize
new738 bytes

Last patch had wrong paths. Fixed it.

idebr’s picture

Status: Needs review » Needs work

The same symptom occurs in the Drupal.AjaxCommands.actionLinkFlash:

if (status === 'success') {
      // Prepare a message element.
      const para = document.createElement('P');
      para.innerText = response.message;
      // Adding this class will initiate a CSS transition.
      para.setAttribute('class', 'js-flag-message');
      // As the transition ends delete the message from the DOM.
      para.addEventListener('animationend', event => event.target.remove(), false);

      // Add message element to the DOM.
      document.querySelector(response.selector).appendChild(para);
    }

The script should not generate a DOM-element here if the response.message is an empty string.

idebr’s picture

Component: Flag Bookmark » Flag core
Status: Needs work » Needs review
StatusFileSize
new2.71 KB
new3.43 KB

Attached patch prevents rendering of an empty message in both the js and nojs scenario.

eworwa’s picture

Hi, I applied the patch from #6 and can confirm that fixes the issue.

Drupal 8.9.13
Flag 8.x-4.0-beta2
Link type: Normal link

seanb’s picture

Status: Needs review » Reviewed & tested by the community

#6 works for me!

  • Berdir committed 9e2c4b6 on 8.x-4.x authored by idebr
    Issue #3157753 by pminf, idebr: Flag sets message although text is empty
    
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

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