ExportAction.php in Content Synchronizer 3.x
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\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TempStore\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, ExportManager $exportManager) {
$this->currentUser = $current_user;
$this->tempStore = $temp_store_factory
->get(ExportConfirmForm::FORM_ID);
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->exportManager = $exportManager;
}
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('tempstore.private'), $container
->get('current_user'), $container
->get(ExportManager::SERVICE_NAME));
}
}