feat: #3104486 Put a term the widget creates under a chosen parent
Adds the parent for new terms asked for in #3104486.
What it does
A new widget setting, Parent of a new term, empty by default and only shown for a taxonomy field. A term the widget creates is put under that parent instead of at the top of the vocabulary.
Core builds an auto created term with no parent, so the ID is carried on #autocreate and the element sets it in a validate that runs after the one of core, where the term first exists.
Three things it does not do:
- A term already saved is never moved.
- A parent something else already set is kept.
- With the setting empty, nothing is touched.
One trap worth knowing
A term carries a parent of 0 for the top of the vocabulary, so parent is never really empty and an isEmpty() check silently skips every term. Only a parent that points at a term counts as one already given. The kernel test fails with 0 is identical to 1 if that check is put back.
Verified on Drupal 11.4.5
| check | result |
|---|---|
| New term with the setting on | Blizzard (8) under Weather (5) |
| New term with the setting empty | Drizzle (9) at the top |
| Terms picked from the list | untouched |
Test coverage
tests/src/Kernel/AutocreateParentTest.php, four cases: the parent is set, no setting leaves the term at the top, an existing parent is kept, a saved term is not moved. Driven at the element rather than through a browser, because the setting carries a term ID and the browser suite deliberately keeps term IDs out of its fixtures.
What it looks like
On a clean Drupal 11.4.5 site with a Topics vocabulary of fifteen editorial subjects, and "Uncategorised" named as the parent for new terms. A topic an editor invents is filed under it; everything already there stays put.
Checkpoints
- File an issue about this project
- Addition/Change/Update/Fix to this project
- Testing to ensure no regression
- Automated unit/functional testing coverage
- Developer Documentation support on feature change/addition
- User Guide Documentation support on feature change/addition
- UX/UI designer responsibilities
- Accessibility and Readability
- Reviewed by a human
- Code review by maintainers
- Full testing and approval
- Credit contributors
- Review with the product owner
- Update Release Notes
- Release
AI-Generated: Yes (the parent for new terms, its widget setting and its kernel test; reviewed by rajab natshah.)