- Issue created by @keszthelyi
- Merge request !1Issue #3506674: Add NULL return type to getAssociatedEntity(). → (Open) created by keszthelyi
When using a collector for a message template that doesn't have associated entity, the following error happens:
TypeError: Drupal\message_recipient_entity\Plugin\MessageRecipient\CollectorExtender\ExcludeOwner::getAssociatedEntity(): Return value must be of type Drupal\Core\Entity\ContentEntityInterface, null returned in Drupal\message_recipient_entity\Plugin\MessageRecipient\CollectorExtender\ExcludeOwner->getAssociatedEntity() (line 36 of ./modules/contrib/message_recipient/modules/message_recipient_entity/src/MessageAssociatedEntityTrait.php).
The problem is that MessageAssociatedEntityTrait::getAssociatedEntity()
doesn't allow returning NULL, but in reality it can return NULL.
My use case is creating a message via a cron job, where the message template uses the 'Users by roles' collector, but there is no associated entity set for the message. In this case, the error happens when collecting the recipients for the message.
Add NULL to the return type declaration for MessageAssociatedEntityTrait::getAssociatedEntity()
.
Active
1.0
Code