eca-1.0.x-dev/src/Plugin/ECA/EcaPluginBase.php
src/Plugin/ECA/EcaPluginBase.php
<?php
namespace Drupal\eca\Plugin\ECA;
use Drupal\Component\Plugin\PluginBase as DrupalPluginBase;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\eca\EcaState;
use Drupal\eca\Token\TokenInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Base class for ECA provided event and modeller plugins.
*/
abstract class EcaPluginBase extends DrupalPluginBase implements ContainerFactoryPluginInterface {
use StringTranslationTrait;
use DependencySerializationTrait;
/**
* Messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected MessengerInterface $messenger;
/**
* ECA token service.
*
* @var \Drupal\eca\Token\TokenInterface
*/
protected TokenInterface $tokenService;
/**
* Current user account.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $currentUser;
/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* Entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected EntityTypeBundleInfoInterface $entityTypeBundleInfo;
/**
* Symfony request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected RequestStack $requestStack;
/**
* ECA state service.
*
* @var \Drupal\eca\EcaState
*/
protected EcaState $state;
/**
* Constructor for ECA plugins.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param array $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
* @param \Drupal\eca\Token\TokenInterface $token_service
* The ECA token service.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* The current user account.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity bundle info service.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The Symfony request stack.
* @param \Drupal\eca\EcaState $state
* The ECA state service.
*/
final public function __construct(array $configuration, string $plugin_id, array $plugin_definition, MessengerInterface $messenger, TokenInterface $token_service, AccountProxyInterface $current_user, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, RequestStack $requestStack, EcaState $state) {
$this->messenger = $messenger;
$this->tokenService = $token_service;
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
$this->requestStack = $requestStack;
$this->state = $state;
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('messenger'),
$container->get('eca.token_services'),
$container->get('current_user'),
$container->get('entity_type.manager'),
$container->get('entity_type.bundle.info'),
$container->get('request_stack'),
$container->get('eca.state')
);
}
}
