Add a vocabulary filter to a checkbox in the settings for the "Inline entity form - Complex" widget

Created on 5 July 2023, 12 months ago

Problem/Motivation

The "Inline entity form - Complex" widget allows users to add ANY new taxonomy term entities when "Allow users to add new taxonomy term entities." is checked. Even adding terms to vocabularies that cannot actually be referenced by the field.

If we limit the users choices to certain vocabularies

  • the UI will be simpler
  • the users will not be lured into making errors

Steps to reproduce

You have two vocabularies: COLOUR (terms could be red, green, blue) and MAKE (Skoda, VW, Ford).

You have a content type CAR with a taxonomy term reference field called COLOUR. This field is limited to terms from the COLOUR vocabulary.

At Manage fields( /admin/structure/types/manage/event/fields/node.car.field_colour ) the reference method under reference type is set to "use a view" that is only offering terms from the COLOUR vocabulary. A wise choice for a taxonomy reference field called COLOUR.

At Manage form display (/admin/structure/types/manage/car/form-display) the widget for the COLOUR taxonomy term reference is set to "Inline entity form - complex".

Checking "Allow users to add existing taxonomy term entities" works great. If they add a new car they get to choose solely between the colours provided by the (taxonomy term) entity reference view in the taxonomy term reference field. The colour field only offers colour terms. As it should be.

Checking "Allow users to add new taxonomy term entities" doesn't work as well. If the user adds a new car and chooses to add a new taxonomy term he/she gets to add a MAKE term to the colour field. Which is wrong and doesn't work.
The user will think they're adding Toyota to the colour term reference field. But they do not. They are (fortunately) halted by a short error message "You cannot reference this term" (which is very correct).

Proposed resolution

When checking "Allow users to add new taxonomy term entities." in the widget settings at "Manage form display" a way to limit the vocabularies they can actually add terms to should pop up:

_ Allow users to add new taxonomy term entities.
_ Colour
_ Make

If only one vocabulary is checked, the user will never be able to add a term to the wrong vocabulary and will not be met with errors whenever he or she adds a new car.

A simple solution
This solution is simpler than inspecting the (taxonomy term) entity reference view in the taxonomy term reference field in the hopes of spotting a vocabulary filter. Adding our own vocabulary filter is relatively simple.

A less stupid solution
This solution is way better than removing a user's ability to create terms in either the colour or make vocabulary. We should not constrain the user globally. We should constrain the "Inline entity form - complex - Allow users to add new taxonomy term entities" locally.

Remaining tasks

Someone smarter than I and with more "Inline entity form"-experience should think this through and propose the right solution.

User interface changes

A vocabulary filter is added to a checkbox in the settings for the "Inline entity form - Complex" widget.

API changes

None.

Data model changes

Probably none.

✨ Feature request
Status

Active

Version

2.0

Component

User interface

Created by

πŸ‡©πŸ‡°Denmark Steven Snedker

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

Comments & Activities

Production build 0.69.0 2024