Problem/Motivation
There's an edge case when you use this widget for term's parent_term field (using setDisplayConfigurable, it allows to choose the same term (or one of its children) as parent.
This lead to an error on all pages that display the widget or the full tree (because of the _term_reference_tree_get_term_hierarchy infinite recursive loop).
It's similar to "#3372888 Add option to disable sub-items if parent is checked" issue, but with self.
Steps to reproduce
Use this code to enable a term's parent_term.
/**
* Implements hook_entity_base_field_info_alter().
*/
#[Hook('entity_base_field_info_alter')]
public function entityBaseFieldInfoAlter(&$fields, EntityTypeInterface $entity_type): void {
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
if ($entity_type->id() === 'taxonomy_term') {
$fields['parent']->setDisplayConfigurable('form', TRUE);
}
}
Use the term_reference_tree widget for this field.
Edit a term, set the parent term to this term (or one of its children)
Save
Go back to the term list, it should be loading until timeout and return a blank error page (500)
Proposed resolution
Add a validation that prevent self and child referencing, at least for term entities.
Add a limit to the _term_reference_tree_get_term_hierarchy recursion.
Or simply put a warning in the README.md
Comments
Comment #2
o'briat