ExportAction.php in Content Synchronizer 8
File
src/Plugin/Action/ExportAction.php
View source
<?php
namespace Drupal\content_synchronizer\Plugin\Action;
use Drupal\content_synchronizer\Form\ExportConfirmForm;
use Drupal\content_synchronizer\Service\ExportManager;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ExportAction extends ActionBase implements ContainerFactoryPluginInterface {
protected $tempStore;
protected $currentUser;
protected $exportManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory = NULL, AccountInterface $current_user = NULL) {
$this->currentUser = $current_user;
$this->tempStore = $temp_store_factory
->get(ExportConfirmForm::FORM_ID);
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->exportManager = \Drupal::service(ExportManager::SERVICE_NAME);
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
return TRUE;
}
public function executeMultiple(array $entities) {
$info = [
'url' => \Drupal::request()
->getRequestUri(),
'entities' => [],
];
foreach ($entities as $entity) {
$info['entities'][$entity
->getEntityTypeId()][] = $entity
->id();
}
$this->tempStore
->set($this->currentUser
->id(), $info);
}
public function execute($entity = NULL) {
$this
->executeMultiple([
$entity,
]);
}
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'));
}
}