You are here

class Simple in Entityqueue 8

Defines an entity queue handler that manages a single subqueue.

Plugin annotation


@EntityQueueHandler(
  id = "simple",
  title = @Translation("Simple queue"),
  description = @Translation("Provides a queue with a single (fixed) subqueue."),
)

Hierarchy

Expanded class hierarchy of Simple

File

src/Plugin/EntityQueueHandler/Simple.php, line 24

Namespace

Drupal\entityqueue\Plugin\EntityQueueHandler
View source
class Simple extends EntityQueueHandlerBase implements ContainerFactoryPluginInterface {
  use RedirectDestinationTrait;

  /**
   * The entity repository.
   *
   * @var \Drupal\Core\Entity\EntityRepositoryInterface
   */
  protected $entityRepository;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs a Simple queue handler 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\EntityRepositoryInterface $entity_repository
   *   The entity repository.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityRepositoryInterface $entity_repository, ModuleHandlerInterface $module_handler) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->entityRepository = $entity_repository;
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity.repository'), $container
      ->get('module_handler'));
  }

  /**
   * {@inheritdoc}
   */
  public function supportsMultipleSubqueues() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function hasAutomatedSubqueues() {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function getQueueListBuilderOperations() {

    // Simple queues have just one subqueue so we can link directly to the edit
    // form.
    $subqueue = EntitySubqueue::load($this->queue
      ->id());
    $subqueue = $this->entityRepository
      ->getTranslationFromContext($subqueue);
    $operations['edit_subqueue'] = [
      'title' => $this
        ->t('Edit items'),
      'weight' => -9,
      'url' => $subqueue
        ->toUrl('edit-form')
        ->mergeOptions([
        'query' => $this
          ->getRedirectDestination()
          ->getAsArray(),
      ]),
    ];

    // Add a 'Translate' operation if translation is enabled for this queue.
    if ($this->moduleHandler
      ->moduleExists('content_translation') && content_translation_translate_access($subqueue)
      ->isAllowed()) {
      $operations['translate_subqueue'] = [
        'title' => $this
          ->t('Translate subqueue'),
        'url' => $subqueue
          ->toUrl('drupal:content-translation-overview'),
        'weight' => -8,
      ];
    }
    return $operations;
  }

  /**
   * {@inheritdoc}
   */
  public function onQueuePostSave(EntityQueueInterface $queue, EntityStorageInterface $storage, $update = TRUE) {

    // Make sure that every simple queue has a subqueue.
    if ($update) {
      $subqueue = EntitySubqueue::load($queue
        ->id());
      $subqueue
        ->setTitle($queue
        ->label());
    }
    else {
      $subqueue = EntitySubqueue::create([
        'queue' => $queue
          ->id(),
        'name' => $queue
          ->id(),
        'title' => $queue
          ->label(),
        'langcode' => $queue
          ->language()
          ->getId(),
      ]);
    }
    $subqueue
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  public function onQueuePostDelete(EntityQueueInterface $queue, EntityStorageInterface $storage) {

    // Delete the subqueue when the parent queue is deleted.
    if ($subqueue = EntitySubqueue::load($queue
      ->id())) {
      $subqueue
        ->delete();
    }
  }

}

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
EntityQueueHandlerBase::$queue protected property The entity queue that is using this plugin.
EntityQueueHandlerBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 2
EntityQueueHandlerBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
EntityQueueHandlerBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 2
EntityQueueHandlerBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
EntityQueueHandlerBase::onQueuePostLoad public function Acts on loaded entity queues. Overrides EntityQueueHandlerInterface::onQueuePostLoad
EntityQueueHandlerBase::onQueuePreDelete public function Acts on entity queues before they are deleted and before hooks are invoked. Overrides EntityQueueHandlerInterface::onQueuePreDelete
EntityQueueHandlerBase::onQueuePreSave public function Acts on an entity queue before the presave hook is invoked. Overrides EntityQueueHandlerInterface::onQueuePreSave
EntityQueueHandlerBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
EntityQueueHandlerBase::setQueue public function Sets the entity queue that is using this plugin. Overrides EntityQueueHandlerInterface::setQueue
EntityQueueHandlerBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm 2
EntityQueueHandlerBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 1
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.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
Simple::$entityRepository protected property The entity repository.
Simple::$moduleHandler protected property The module handler.
Simple::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
Simple::getQueueListBuilderOperations public function Gets this queue handler's list builder operations. Overrides EntityQueueHandlerBase::getQueueListBuilderOperations
Simple::hasAutomatedSubqueues public function Whether or not the handler contains subqueues with an automated lifecycle. Overrides EntityQueueHandlerInterface::hasAutomatedSubqueues
Simple::onQueuePostDelete public function Acts on deleted entity queues before the delete hook is invoked. Overrides EntityQueueHandlerBase::onQueuePostDelete
Simple::onQueuePostSave public function Acts on an entity queue before the insert or update hook is invoked. Overrides EntityQueueHandlerBase::onQueuePostSave
Simple::supportsMultipleSubqueues public function Whether or not the handler supports multiple subqueues. Overrides EntityQueueHandlerInterface::supportsMultipleSubqueues
Simple::__construct public function Constructs a Simple queue handler object. Overrides EntityQueueHandlerBase::__construct
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.