Score:1

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

pe 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)

Score:0
cn flag

I have a site that basically has the same setup as yours: some flags have fields, and I use the Field entry form link type to let the user set the fields on flagging.

However, setting the fields on unflagging makes no sense, so I want a direct unflag link.

Setup

  1. Go to the admin edit page for your flag at /admin/structure/flags/manage/.
  2. For Link Type, use Field Entry Form.

This will let users edit the fields when they flag, but not show the fields when unflagging.

I'm pretty sure that's all you have to do. This is definitely working on my site, so if this is not enough, let me know and I'll dig through my code and see what I changed. (I wrote it a couple years ago, so I don't remember it so well.)

pe flag
Thanks, but already have that box enabled. What do you have selected under 'Form behavior'? Also, on the chance that this is bug, what ver of Flag module are you using and what version of Drupal? (I'm on 8.x-4.0-beta3 and D 9.3.12 at the moment)
cn flag
Form behavior is set to "New page". Also running 4.0-beta3 + 9.3.12.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.