class CourierTemplateCollection in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/Plugin/Action/CourierTemplateCollection.php \Drupal\rng\Plugin\Action\CourierTemplateCollection
- 3.x src/Plugin/Action/CourierTemplateCollection.php \Drupal\rng\Plugin\Action\CourierTemplateCollection
Creates a template collection and provides a user interface to its templates.
Plugin annotation
@Action(
id = "rng_courier_message",
label = @Translation("Send message"),
type = "registration"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Action\ConfigurableActionBase implements ConfigurableInterface, ConfigurablePluginInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\rng\Plugin\Action\CourierTemplateCollection implements ContainerFactoryPluginInterface
- class \Drupal\Core\Action\ConfigurableActionBase implements ConfigurableInterface, ConfigurablePluginInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CourierTemplateCollection
1 file declares its use of CourierTemplateCollection
File
- src/
Plugin/ Action/ CourierTemplateCollection.php, line 25
Namespace
Drupal\rng\Plugin\ActionView source
class CourierTemplateCollection extends ConfigurableActionBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The RNG event manager.
*
* @var \Drupal\rng\EventManagerInterface
*/
protected $eventManager;
/**
* The courier manager.
*
* @var \Drupal\courier\Service\CourierManagerInterface
*/
protected $courierManager;
/**
* Constructs a RegistrantBasicEmail object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\rng\EventManagerInterface $event_manager
* The RNG event manager.
* @param \Drupal\courier\Service\CourierManagerInterface $courier_manager
* The courier manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, EventManagerInterface $event_manager, CourierManagerInterface $courier_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityManager = $entity_manager;
$this->eventManager = $event_manager;
$this->courierManager = $courier_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity.manager'), $container
->get('rng.event_manager'), $container
->get('courier.manager'));
}
/**
* {@inheritdoc}
*
* @return array
* - template_collection: integer: ID of a courier_template_collection
* entity. Automatically filled after first submission.
*/
public function defaultConfiguration() {
return array(
'template_collection' => NULL,
);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
if ($template_collection = $this
->getTemplateCollection()) {
$form['template_collection']['#markup'] = $this
->t('Template collection #@id', [
'@id' => $template_collection
->id(),
]);
}
else {
drupal_set_message('No template collection entity found.', 'warning');
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$configuration = $this
->getConfiguration();
// Create new.
if (!isset($configuration['template_collection'])) {
$template_collection = TemplateCollection::create();
if ($template_collection
->save()) {
$this->courierManager
->addTemplates($template_collection);
$template_collection
->save();
}
$this->configuration['template_collection'] = $template_collection
->id();
}
}
/**
* Sends the message.
*
* @param array $context
* An associative array defining context.
* - \Drupal\rng\RegistrationInterface[] registrations: An array of
* registrations to send the message.
*/
public function execute($context = NULL) {
if (!isset($context['registrations'])) {
return;
}
if (!is_array($context['registrations'])) {
return;
}
if ($collection_original = $this
->getTemplateCollection()) {
foreach ($context['registrations'] as $registration) {
$options = [];
/** @var \Drupal\rng\RegistrationInterface $registration */
if (($event = $registration
->getEvent()) instanceof EntityInterface) {
$event_meta = $this->eventManager
->getMeta($event);
$options['channels']['courier_email']['reply_to'] = $event_meta
->getReplyTo();
$collection_original
->setTokenValue($event
->getEntityTypeId(), $event);
}
$collection = clone $collection_original;
$collection
->setTokenValue('registration', $registration);
foreach ($registration
->getRegistrants() as $registrant) {
$identity = $registrant
->getIdentity();
$this->courierManager
->sendMessage($collection, $identity, $options);
}
}
}
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
return FALSE;
}
/**
* Get the courier_template_collection object associated with this action.
*
* @return \Drupal\courier\TemplateCollectionInterface|NULL
* A courier_template_collection object. NULL if it has not been created.
*/
public function getTemplateCollection() {
if (isset($this->configuration['template_collection'])) {
return $this->entityManager
->getStorage('courier_template_collection')
->load($this->configuration['template_collection']);
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActionBase:: |
public | function |
Executes the plugin for an array of objects. Overrides ActionInterface:: |
3 |
ConfigurableActionBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
1 |
ConfigurableActionBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ConfigurableActionBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ConfigurableActionBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
CourierTemplateCollection:: |
protected | property | The courier manager. | |
CourierTemplateCollection:: |
protected | property | The entity type manager. | |
CourierTemplateCollection:: |
protected | property | The RNG event manager. | |
CourierTemplateCollection:: |
public | function |
Checks object access. Overrides ActionInterface:: |
|
CourierTemplateCollection:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
CourierTemplateCollection:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
CourierTemplateCollection:: |
public | function |
Overrides ConfigurableActionBase:: |
|
CourierTemplateCollection:: |
public | function |
Sends the message. Overrides ExecutableInterface:: |
|
CourierTemplateCollection:: |
public | function | Get the courier_template_collection object associated with this action. | |
CourierTemplateCollection:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
CourierTemplateCollection:: |
public | function |
Constructs a RegistrantBasicEmail object. Overrides ConfigurableActionBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |