EmailEventManager.php in Commerce Email 8
File
src/EmailEventManager.php
View source
<?php
namespace Drupal\commerce_email;
use Drupal\commerce_email\Annotation\CommerceEmailEvent;
use Drupal\commerce_email\Plugin\Commerce\EmailEvent\EmailEventInterface;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class EmailEventManager extends DefaultPluginManager {
protected $entityTypeManager;
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct('Plugin/Commerce/EmailEvent', $namespaces, $module_handler, EmailEventInterface::class, CommerceEmailEvent::class);
$this
->alterInfo('commerce_email_event_info');
$this
->setCacheBackend($cache_backend, 'commerce_email_event_plugins');
$this->entityTypeManager = $entity_type_manager;
}
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
foreach ([
'id',
'label',
'entity_type',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new PluginException(sprintf('The condition "%s" must define the "%s" property.', $plugin_id, $required_property));
}
}
$entity_type_id = $definition['entity_type'];
if (!$this->entityTypeManager
->getDefinition($entity_type_id)) {
throw new PluginException(sprintf('The condition "%s" must specify a valid entity type, "%s" given.', $plugin_id, $entity_type_id));
}
}
}