public function LastRevisionAuthor::prepareRecipients in Workbench Email 2.x
Same name and namespace in other branches
- 8 src/Plugin/RecipientType/LastRevisionAuthor.php \Drupal\workbench_email\Plugin\RecipientType\LastRevisionAuthor::prepareRecipients()
Returns email address(s) matching this recipient type's configuration.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: Entity being transitioned.
\Drupal\workbench_email\TemplateInterface $template: Template being used.
Overrides RecipientTypeBase::prepareRecipients
File
- src/
Plugin/ RecipientType/ LastRevisionAuthor.php, line 55
Class
- LastRevisionAuthor
- Defines a plugin for mailing to last revision author.
Namespace
Drupal\workbench_email\Plugin\RecipientTypeCode
public function prepareRecipients(ContentEntityInterface $entity, TemplateInterface $template) {
$entityStorage = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId());
$id_key = $entity
->getEntityType()
->getKey('id');
if (!$id_key) {
return [];
}
$revisions = $entityStorage
->getQuery()
->condition($id_key, $entity
->id())
->accessCheck(FALSE)
->allRevisions()
->execute();
ksort($revisions);
// Remove current revision.
array_pop($revisions);
$revision_ids = array_keys($revisions);
$revision_id = array_pop($revision_ids);
if ($revision_id && ($lastRevision = $entityStorage
->loadRevision($revision_id)) && $lastRevision instanceof RevisionLogInterface) {
return [
$lastRevision
->getRevisionUser()
->getEmail(),
];
}
return [];
}