protected function MessageDigestTrait::getUserMessagesByNotifier in Message Digest 8
Returns the messages that will be includes in the user's next digest.
Parameters
\Drupal\message_digest\Plugin\Notifier\DigestInterface $notifier: The digest notifier that is responsible for sending out the messages.
int $uid: The ID of the user for which to return the messages.
string $entity_type: Optional entity type. If supplied along with the $label property this can be used to return only messages that refer to the given entity.
string $label: Optional entity label. If supplied along with the $entity_type property this can be used to return only messages that refer to the given entity.
Return value
\Drupal\message\MessageInterface[] The messages.
4 calls to MessageDigestTrait::getUserMessagesByNotifier()
- MessageDigestSubContext::assertDigestContains in ./
message_digest.behat.inc - Checks that the digest for a user contains a certain message.
- MessageDigestSubContext::assertDigestEmpty in ./
message_digest.behat.inc - Checks that the given digest for a user does not contain any messages.
- MessageDigestSubContext::assertDigestNotContains in ./
message_digest.behat.inc - Checks that the digest for a user does not contain a certain message.
- MessageDigestTrait::countAllUndeliveredDigestMessages in src/
Traits/ MessageDigestTrait.php - Returns the total number of undelivered digest messages.
File
- src/
Traits/ MessageDigestTrait.php, line 91
Class
- MessageDigestTrait
- Methods useful for testing and integrating the Message Digest module.
Namespace
Drupal\message_digest\TraitsCode
protected function getUserMessagesByNotifier(DigestInterface $notifier, $uid, $entity_type = NULL, $label = NULL) {
// We can't use `$notifier->getEndTime()` since the Behat request has been
// started earlier than the Drupal requests that created the digests.
$digests = $notifier
->aggregate($uid, time());
// Optionally filter by entity.
if (!empty($entity_type) && !empty($label)) {
$entity = $this
->getEntityByLabel($entity_type, $label);
$message_ids = !empty($digests[$entity_type][$entity
->id()]) ? $digests[$entity_type][$entity
->id()] : [];
}
else {
$message_ids = [];
foreach ($digests as $entity_type => $entities) {
foreach ($entities as $entity_id => $messages) {
$message_ids = array_merge($message_ids, $messages);
}
}
}
return $this
->getMessages($message_ids);
}