- Issue created by @alecsmrekar
- 🇵🇱Poland Graber
I think for the sake of correct docs we should change the return type to
?EntityInterface
as proposed by Alec but the real issue here is thatDrupal\group\Plugin\Group\RelationHandlerDefault::getRelationshipLabel()
doesn't account for the situation when NULL is actually returned and that can always be a case. Can we change it to something like:/** * {@inheritdoc} */ public function getRelationshipLabel(GroupRelationshipInterface $group_relationship) { $entity = $group_relationship->getEntity(); if ($entity === NULL) { $label = $this->t('Deleted entity: @plugin (@id)', [ '@plugin' => $group_relationship->getPluginId(), '@id' => $group_relationship->getEntityId(), ]; } else { $label = $group_relationship->getEntity()->label(); } return $label; }
By the way,
Drupal\group\Plugin\Group\RelationHandler\UiTextProviderInterface::getRelationshipLabel()
return type is also incorrect as it can return a string and not only\Drupal\Core\StringTranslation\TranslatableMarkup
. I'd probably start using type hints instead of those misleading comments across the entire project.
I'd say let's solve the issue withgetRelationshipLabel
here and leave type hints to the maintainer as it's a much bigger general work and out of scope here. - 🇸🇮Slovenia alecsmrekar
but the real issue here is that Drupal\group\Plugin\Group\RelationHandlerDefault::getRelationshipLabel() doesn't account for the situation when NULL is actually returned
In my view
getRelationshipLabel
is not wrong, it's respecting the return type of theGroupRelationship::getEntity
method. Why check if something is NULL if the called function says it'll never be NULL. The called functionGroupRelationship::getEntity
is at fault here.Adding this check would prevent the issue I reported in the issue description, but I think we should avoid tolerating wrong types, since types are very good guardrails.
- 🇵🇱Poland Graber
The thing is that every entity loading method can return NULL. See
Drupal\Core\Entity\EntityStorageInterface::load()
that is at the very bottom of all this and has a correct return type specified. - 🇵🇱Poland Graber
OFC you can open a generic issue to correct return types across the entire module as we found 2 already.
Made a patch with #2 proposal; just fixed a missing ")".
Tested on my own envirotment (Under Drupal 10.2.6 with Group 2.2.2) in wich I had this problem.
The "call of label() on Null" problem after deleting content is now gone.