Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
A site sells printed issues of a magazine. When all the issues are sold they want to keep all the information about the magazine issue but want to remove everything related to selling (not just "Add to cart" button but the price info too).
The current solution to that is an inline entity form multiple value product reference field. But because we need to reference only one product entity this solution feels a little bit hacky and would be better to use a single value inline entity reference which makes possible to remove its value when it is not needed any more.
Comment | File | Size | Author |
---|---|---|---|
#6 | inline_entity_form-n2348915-6.patch | 2.4 KB | DamienMcKenna |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedI went ahead with single value inline entity reference and added extra code via hook_form_alter() to remove single value inline entity reference when their fields are empty... it works for my client's site now but I do not feel that it is optimal and wonder if there is a better way of doing this or there are plans for single value inline entity reference to cater for these use case?
What I have done so far:
1. Content-type created with optional single value inline entity reference field.
2. Added extra form submit handlers with hook_form_alter():
3. I added 2 submit handlers as the first one calls before anything else and deletes the referenced entity, and the second one actually removes the reference to the entity.
I would think that the second submit hook is less than optimal, as it is potentially writing to the database a second time?
Comment #2
DamienMcKennaI'd say this is a bug, or at least the field settings should indicate that it won't be editable.
Comment #3
bojanz CreditAttribution: bojanz commentedThe single widget only works for required fields, which means that there must always be a value.
Optional fields can use the normal, multiple widget.
Comment #4
DamienMcKenna@bojanz: In that case it's a UI problem as this is not made clear.
Comment #5
bojanz CreditAttribution: bojanz commentedWhat's your suggestion? Adding a warning above widget settings? The widget label doesn't leave a lot of room to communicate intent.
Comment #6
DamienMcKennaSomething like this? The widget label change might honestly be enough, but this also adds descriptions to the widget form.
Comment #7
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 4 year old patch in #6 to inline_entity_form.module applied cleanly to the latest inline_entity_form 7.x-1.x-dev and is a very reasonable fix for this issue so changing the status to RTBC.
Comment #9
ram4nd CreditAttribution: ram4nd as a volunteer commentedComment #10
dwwThanks for this improvement!
Is there a D9+ version of this? Seems weird to be adding new features for D7 that don’t have parity in D9+. It’d become a regression for folks that rely on this in D7 when they try to upgrade.