You are here

Author.php in Workbench Email 2.x

Same filename and directory in other branches
  1. 8 src/Plugin/RecipientType/Author.php

File

src/Plugin/RecipientType/Author.php
View source
<?php

namespace Drupal\workbench_email\Plugin\RecipientType;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\user\EntityOwnerInterface;
use Drupal\workbench_email\Plugin\RecipientTypeBase;
use Drupal\workbench_email\TemplateInterface;

/**
 * Provides a recipient type of the content author.
 *
 * @RecipientType(
 *   id = "author",
 *   title = @Translation("Author"),
 *   description = @Translation("Send to entity author/owner."),
 * )
 */
class Author extends RecipientTypeBase {

  /**
   * {@inheritdoc}
   */
  public function prepareRecipients(ContentEntityInterface $entity, TemplateInterface $template) {
    $recipients = [];
    if ($this
      ->isEnabled() && $entity instanceof EntityOwnerInterface) {
      if (!$entity
        ->getOwner()
        ->isAnonymous()) {
        $recipients[] = $entity
          ->getOwner()
          ->getEmail();
      }
    }
    return $recipients;
  }

}

Classes

Namesort descending Description
Author Provides a recipient type of the content author.