Can ECA be used to save new taxonomy terms before the parent entity is saved?

Created on 27 February 2024, 4 months ago
Updated 20 March 2024, 3 months ago

Problem/Motivation

A very common usability issue exists in Drupal if you use Paragraphs, ECK, IEF (i.e., for creating Product Variations on Commerce Product entities) regarding new taxonomy terms (and perhaps less common, other referenced entities).

For example, let's say a "recipe" node holds a multi-value reference field to ECK entities called "step" that are created on the fly. These entities hold a field called: Ingredient (taxonomy), quantity (decimal), and unit (list). The "Ingredient" field allows new terms to be created.

Let's say we add a recipe with 4 steps, both the first step and the last step involve the ingredient "sugar" because we're going to sprinkle some on top. Let's say sugar is a new term, and we enter it as we add the first "step" ECK entity. We select "add another" and work down the list. At the final step entity, we again enter "sugar" as the ingredient.

Now, the term "sugar" still doesn't exist, even though we entered it in step 1 because the "Step" entities won't get saved before we save the parent "Recipe" node. Only after we save the recipe node, will the term be created. That of course means that we'll end up with two "sugar" terms, as the last referenced entity will trigger the same process of saving "sugar" as a new term with the same name.

This behavior is infinitely confusing for content creators and end-users, and it results not only in duplicate terms but all sorts of interface distortions (if we render the ingredients for the recipe, "sugar" will be listed twice with different quantities in, for instance, the "What you'll need" section (assuming the node has one).

I'm not too familiar yet with the ECA Form sub-module and I suspect there will be a lot of intricacies involved in getting Drupal to save referenced entities before the parent entity is saved. So my question is if this is possible at all, and if so, can ECA do it? Can ECA evaluate if a term is new when it is entered, and if so, save the entity right away instead of waiting until the entire form is submitted so it is available right away to subsequent "sub"-entities?

I have so far not found an existing solution to this problem which I'm sure is not rare, considering the popularity of paragraphs, commerce, etc.

Thanks in advance for any insights in this.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ’¬ Support request
Status

Fixed

Version

1.1

Component

Documentation

Created by

πŸ‡ΉπŸ‡­Thailand AlfTheCat

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @AlfTheCat
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thanks for raising this question @AlfTheCat. First, let me not that all 3 (paragraphs, eck, ief) are actually the same: it all is IEF, so we can focus on that single component for the discussion.

    Should we try and interfere with the submission process of IEF? My opinion is a strong NO. That whole process is already as complex as it can get. Hooking into that can only cause trouble.

    Of course, you have a valid use case here. I'm sure you're not alone with that, there are certainly many others having similar requirements. Therefore, I'd propose that as a feature request with the IEF module in a way that in the complex IEF mode, there should be a config option to immediately save that entity. This would allow for subsequent components in the parent form to choose the "Select entity" instead of creating again a new one.

    Consequently, such referenced entities, if they get stored immediately, they will remain in your system even if the parent form will never be submitted. But that's most likely what you want, at least in your use case above.

  • Status changed to Fixed 4 months ago
  • πŸ‡ΉπŸ‡­Thailand AlfTheCat

    Hi Jurgen, thank you very much for the insight. I hadn't thought about filing this as a feature request for IEF but that seems indeed the best place to do it. I browsed through the queue there and didn't see any similar issue yet so I created ✨ Save newly created entities immediately Active .

    Let's hope it will lead to a solution that can benefit many :)

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thx

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

Production build 0.69.0 2024