Score:0

How to create a taxonomy term from a webform

pe flag

New to Webform. What I'm trying to do is build a somewhat simple site content-collecting tool using Webform. So users would 'collect' nodes by submitting forms on them. This appears to be easy to do. However, I need them to be able to group their nodes/form submissions into sets I'm calling 'folders.'

I could do this a couple of ways:

  • a content type of Folder + an entity reference element on the webform to allow selection of existing "folder" items.
  • a vocabulary of Folder + entity ref element on the webform to select terms

But users also need to be able to create new folders. That's where I'm stuck. How can I make the form/form-element allow users to create a new folder?

I see another way: what if instead of entity, they just have a form element of Folder, that they add items to? But this needs to be user-specific, so the list field element would would need to accumulate items (Folders) per user.

So, how would I do that? Is there a better way?

(Thought about Flag module first, but then users would need the ability to create new flags but somehow not have access to the whole flag configuration UI.)

Score:2
pe flag

It appears that three modules can work together in Drupal 8/9 to do the job I've described.

  • Flag: to give users ability to mark content, with an entity ref field for the category. (Per Patrick Kenny above: thanks Patrick!)
  • Webform Content Creator: to create term entities from webform submissions: this is so users can create categories on the fly without navigating to a node create page then returning to the node they wanted to collect/flag.
  • Private Taxonomy Terms: to limit term edit access to the creator of the term

Views plays a key role also, because I'm mostly controlling access to collected content via Views and filters rather than the permissions system. This isn't really "access control" per se, but should be private enough for this project. The only permission-based control we need is to grant role(s) the ability to view the term but only grant ability to edit the term to its creator.

This approach might seem overly heavy, since Webform already creates entities. But, as far as I can tell, there isn't a way to set up "edit own submissions" permission on a webform and also grant "view any submission" on that form's submissions. But maybe I'm wrong about that?

Edit: I am wrong about that! ... so will have to see if the necessary Views filters can work on webform submissions. I'm going to leave this one marked as the solution since it answer the original question about creating taxonomy terms.

pe flag
Probably also need to clarify: a challenge was to filter the entity ref field on the flagging so that users would only see their own categories there, yet also provide a way to create new ones. Views-filtered entity ref fields don't allow that. Hence, Webform for the purpose of creating new categories, while *selecting* categories is a Views filtered field.
Score:0
cn flag

You want users to be able to "collect" content and then you want to organize those collections by category. That sounds a lot closer to Flag module than Webform.

then users would need the ability to create new flags but somehow not have access to the whole flag configuration UI.

Users do not need the ability to create new flags.

Flags are entities, so they can have fields added to them. So you create one flag, Collect content, and then you add an entity reference field, category, which is a taxonomy term reference to a taxonomy term vocabulary, Private tags or something like that.

Private tags has custom permissions so that users can only see terms they have created. Also, you can make these taxonomy terms unique per user, as it's a big UX fail to let users have multiple categories with the exact same name.

Flags also has basic Views support, although it can be tricky to use and might require some customization.

pe flag
Thanks. My brain is still insisting that if users want to have multiple separate collections, they'll need ability to create new flags. But maybe you've solved this with taxon terms... To make sure I understand, the 'category' serve the purpose of a 'collection,' so there would be a vocab called, say 'collection category' that users would have permission to add terms to - with access control via Private tags. I think I get it. I wonder, though, if the same couldn't be done with a Webform element. But Flags + taxonomy + Private tags may be a more straightforward way to do it.
pe flag
I'm not able to find a Private tags module.
cn flag
@aharown07 There is no "private tags" module; I just made up a name for the taxonomy vocabulary you could create, and I called that "private tags." The access control you will have to code yourself, but there is an example in the linked question.
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.