You are here

class EntityReferenceUser in Workbench Email 8

Same name and namespace in other branches
  1. 2.x src/Plugin/RecipientType/EntityReferenceUser.php \Drupal\workbench_email\Plugin\RecipientType\EntityReferenceUser

Provides a recipient type based on entity reference fields.

Plugin annotation


@RecipientType(
  id = "entity_reference_user",
  title = @Translation("Entity Reference: User"),
  description = @Translation("Send to users referenced in an entity reference field."),
  settings = {
    "fields" = {},
  },
)

Hierarchy

Expanded class hierarchy of EntityReferenceUser

File

src/Plugin/RecipientType/EntityReferenceUser.php, line 20

Namespace

Drupal\workbench_email\Plugin\RecipientType
View source
class EntityReferenceUser extends EmailField {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {

    // Add the fields.
    $fields = $this->entityFieldManager
      ->getFieldMapByFieldType('entity_reference');
    $field_options = [];
    foreach ($fields as $entity_type_id => $entity_type_fields) {
      $entity_type = $this->entityTypeManager
        ->getDefinition($entity_type_id);
      if (!$this
        ->isModeratableEntityType($entity_type)) {

        // These fields are irrelevant, the entity type isn't moderated.
        continue;
      }
      $base = $this->entityFieldManager
        ->getBaseFieldDefinitions($entity_type_id);
      foreach ($entity_type_fields as $field_name => $field_detail) {
        if (in_array($field_name, array_keys($base), TRUE)) {
          if ($base[$field_name]
            ->getSetting('target_type') !== 'user') {
            continue;
          }
          $field_options[$entity_type_id . ':' . $field_name] = $base[$field_name]
            ->getLabel() . ' (' . $entity_type
            ->getLabel() . ')';
          continue;
        }
        $sample_bundle = reset($field_detail['bundles']);
        $bundle_fields = $this->entityFieldManager
          ->getFieldDefinitions($entity_type_id, $sample_bundle);
        if (!isset($bundle_fields[$field_name])) {

          // Stale field map reference.
          continue;
        }
        $sample_field = $bundle_fields[$field_name];
        if ($sample_field
          ->getSetting('target_type') !== 'user') {
          continue;
        }
        $field_options[$entity_type_id . ':' . $field_name] = $sample_field
          ->label() . ' (' . $entity_type
          ->getLabel() . ')';
      }
    }
    return [
      'fields' => [
        '#type' => 'checkboxes',
        '#title' => $this
          ->t('Entity Reference User Fields'),
        '#description' => $this
          ->t('Send to users referenced by the selected fields.'),
        '#options' => $field_options,
        '#default_value' => $this
          ->getFields(),
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function getEmailFromFieldItem(FieldItemInterface $field_item) {
    return $field_item->entity
      ->getEmail();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EmailField::$entityFieldManager protected property The entity field manager.
EmailField::$entityTypeManager protected property The entity type manager.
EmailField::$moderationInfo protected property Moderation info service.
EmailField::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides RecipientTypeBase::calculateDependencies
EmailField::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
EmailField::getFields protected function Gets value of roles.
EmailField::isModeratableEntityType protected function Determines if an entity type has been marked as moderatable.
EmailField::onDependencyRemoval public function Informs the plugin that a dependency of the recipient type will be deleted. Overrides RecipientTypeBase::onDependencyRemoval
EmailField::prepareRecipients public function Returns email address(s) matching this recipient type's configuration. Overrides RecipientTypeBase::prepareRecipients
EmailField::setFields protected function Sets roles.
EmailField::submitConfigurationForm public function Form submission handler. Overrides RecipientTypeBase::submitConfigurationForm
EmailField::__construct public function Constructs a new EmailField object. Overrides RecipientTypeBase::__construct
EntityReferenceUser::buildConfigurationForm public function Generates a recipient types's settings form. Overrides EmailField::buildConfigurationForm
EntityReferenceUser::getEmailFromFieldItem protected function Overrides EmailField::getEmailFromFieldItem
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PluginWithFormsTrait::getFormClass public function
PluginWithFormsTrait::hasFormClass public function
RecipientTypeBase::$provider public property The name of the provider that owns this recipient type.
RecipientTypeBase::$settings public property An associative array containing the configured settings of this recipient type.
RecipientTypeBase::$status public property A Boolean indicating whether this recipient type is enabled.
RecipientTypeBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
RecipientTypeBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
RecipientTypeBase::getDescription public function Returns the administrative description for this recipient type plugin. Overrides RecipientTypeInterface::getDescription
RecipientTypeBase::getLabel public function Returns the administrative label for this recipient type plugin. Overrides RecipientTypeInterface::getLabel
RecipientTypeBase::isEnabled public function Checks status. Overrides RecipientTypeInterface::isEnabled
RecipientTypeBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
RecipientTypeBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.