- 🇩🇪Germany kmetz
I've encountered this issue when I called
isRoot()
on a not-yet saved subgroup (during insert).I think that
isRoot()
should catchMalformedLeafException
and return FALSE, same asisLeaf()
does when it callswrapLeaf()
.Both methods for reference:
/** * {@inheritdoc} */ public function isLeaf(EntityInterface $entity) { $this->verify($entity); try { $this->wrapLeaf($entity); } catch (MalformedLeafException $e) { return FALSE; } return TRUE; } /** * {@inheritdoc} */ public function isRoot(EntityInterface $entity) { $this->verify($entity); return $this->wrapLeaf($entity)->getDepth() === 0; }
- 🇩🇪Germany kmetz
Also when calling
getParent()
on an unsaved subgroup -getParent()
does callwrapLeaf()
indirectly viaisRoot()
, and directly afterwards, in which case aMalformedLeafException
should maybe be catched as well?Unsure, since the unsaved subgroup technically does (or a bit later will) have a parent, but all of subgroup_depth / subgroup_left / subgroup_right / subgroup_tree are empty at the point of checking for a parent group.
I'm now use a workaround, by catching
InvalidLeafException | MalformedLeafException
when I check for parents of (potenitally) unsaved (isNew() === true) groups, which I know can be ignored in my special case.