next-1.0.0-alpha2/src/Plugin/PreviewUrlGeneratorBase.php
src/Plugin/PreviewUrlGeneratorBase.php
<?php
namespace Drupal\next\Plugin;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\next\PreviewSecretGeneratorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a base class for preview_url_generator plugins.
*/
abstract class PreviewUrlGeneratorBase extends PluginBase implements PreviewUrlGeneratorInterface, ContainerFactoryPluginInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $currentUser;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected TimeInterface $time;
/**
* The preview secret generator.
*
* @var \Drupal\next\PreviewSecretGeneratorInterface
*/
protected PreviewSecretGeneratorInterface $previewSecretGenerator;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected EntityTypeManagerInterface $entityTypeManager;
/**
* ConfigurablePreviewUrlGeneratorBase constructor.
*
* @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\Session\AccountProxyInterface $current_user
* The current user.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\next\PreviewSecretGeneratorInterface $preview_secret_generator
* The preview secret generator.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountProxyInterface $current_user, TimeInterface $time, PreviewSecretGeneratorInterface $preview_secret_generator, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
$this->time = $time;
$this->previewSecretGenerator = $preview_secret_generator;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('current_user'), $container->get('datetime.time'), $container->get('next.preview_secret_generator'), $container->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getId(): string {
return $this->pluginDefinition['id'];
}
/**
* {@inheritdoc}
*/
public function getLabel(): string {
return $this->pluginDefinition['label'];
}
/**
* {@inheritdoc}
*/
public function getDescription(): string {
return $this->pluginDefinition['description'];
}
}
