BaseJobAction.php in TMGMT Extension Suite 8.2
File
src/Plugin/Action/BaseJobAction.php
View source
<?php
namespace Drupal\tmgmt_extension_suit\Plugin\Action;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\PrivateTempStoreFactory;
abstract class BaseJobAction extends ActionBase implements ContainerFactoryPluginInterface {
protected $tempStoreFactory;
protected $currentUser;
public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
$this->tempStoreFactory = $temp_store_factory;
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = content_translation_translate_access($object);
return TRUE;
}
protected abstract function getTempStoreName($entity_type = '');
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('user.private_tempstore'), $container
->get('current_user'));
}
public function executeMultiple(array $entities) {
$ids = [];
foreach ($entities as $entity) {
$ids[$entity
->id()] = $entity
->getEntityTypeId();
}
$entity = reset($entities);
if ($entity instanceof EntityInterface) {
$entity_type = $entity
->getEntityTypeId();
}
$this->tempStoreFactory
->get($this
->getTempStoreName($entity_type))
->set($this->currentUser
->id(), $ids);
}
public function execute(ContentEntityInterface $entity = NULL) {
$this
->executeMultiple([
$entity,
]);
}
}