View source
<?php
namespace Drupal\entityqueue\Plugin\EntityQueueHandler;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Routing\RedirectDestinationTrait;
use Drupal\entityqueue\Entity\EntitySubqueue;
use Drupal\entityqueue\EntityQueueHandlerBase;
use Drupal\entityqueue\EntityQueueInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Simple extends EntityQueueHandlerBase implements ContainerFactoryPluginInterface {
use RedirectDestinationTrait;
protected $entityRepository;
protected $moduleHandler;
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;
}
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'));
}
public function supportsMultipleSubqueues() {
return FALSE;
}
public function hasAutomatedSubqueues() {
return TRUE;
}
public function getQueueListBuilderOperations() {
$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(),
]),
];
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;
}
public function onQueuePostSave(EntityQueueInterface $queue, EntityStorageInterface $storage, $update = TRUE) {
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();
}
public function onQueuePostDelete(EntityQueueInterface $queue, EntityStorageInterface $storage) {
if ($subqueue = EntitySubqueue::load($queue
->id())) {
$subqueue
->delete();
}
}
}