How can I use a different dialog for flag removal than for setting the flag?

My project has a special flag with an entity reference field in it to nodes of a content type I’ll call here "bucket."

How it works:

  • The flag "add to bucket" appears on nodes of type Article
  • If the user wants to bucket the node, they click the ‘add to bucket’ flag
  • The ‘add to bucket’ flag is configured to display a dialog (at the moment, not modal)
  • The dialog allows them to select a bucket; on submission of the dialog, the flagging is created with a relationship to the selected bucket

All of that works great (views allows the user to see Articles in each bucket)

The problem arises when the user decides to remove the flagging from the node.

Flag module uses the same dialog, only with a ‘remove’ button added to it. Since it’s the same dialog used to add the flagging, it has the entity reference field with the list of buckets… but this is meaningless. Clicking ‘remove’ deletes the flagging regardless of what ‘bucket’ it’s related to.

The dialog also has a "save" button on it that doesn’t make sense in that context.

I’d like users to not see the entity reference field when removing the flag… and also not see the save button.

Option 1: maybe there is a setting in the flag configuration for this and I am going to facepalm . . . but I am not seeing the setting, if it exists. (Fatigue blindness? I have done it before!)

Option 2: use CSS to hide those two elements. Problem: there does not appear to be classes to distinguish the removal context from the add context. Maybe I’m missing something there? I can see that in my theme form.html.twig is handling individual form elements, but I don’t see what template is generating the dialog. With that info, maybe some logic can go into the template to create some classes for the unflagging?

Option 3: get it to use a different form for the unflagging. … How to do that?

Maybe there’s a module that can do this, or a combination of them? I haven’t found one.

If I’d need to code a module, any advice on the general approach? (Note: I’ve coded maybe two tiny modules before, mostly cut and paste, so… skill level for that is probably "below novice." So use small words, lol)

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

How can I use a different dialog for flag removal than for setting the flag?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.