ConvertBundlesActionBase.php in Convert Bundles 8
File
src/Plugin/Action/ConvertBundlesActionBase.php
View source
<?php
namespace Drupal\convert_bundles\Plugin\Action;
use Drupal\Core\Action\ConfigurableActionBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\Core\Session\SessionManagerInterface;
use Drupal\Core\Form\FormStateInterface;
class ConvertBundlesActionBase extends ConfigurableActionBase implements ContainerFactoryPluginInterface {
protected $pluginId;
protected $pluginDefinition;
protected $configuration;
protected $tempStoreFactory;
private $sessionManager;
private $currentUser;
public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, SessionManagerInterface $session_manager, AccountInterface $current_user) {
$this->configuration = $configuration;
$this->pluginId = $plugin_id;
$this->pluginDefinition = $plugin_definition;
$this->tempStoreFactory = $temp_store_factory;
$this->sessionManager = $session_manager;
$this->currentUser = $current_user;
}
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('session_manager'), $container
->get('current_user'));
}
public function executeMultiple(array $entities) {
$ids = [];
foreach ($entities as $entity) {
$ids[$entity
->id()] = $entity;
}
$this->tempStoreFactory
->get('convert_bundles_ids')
->set($this->currentUser
->id(), $ids);
}
public function execute(ContentEntityInterface $entity = NULL) {
$this
->executeMultiple([
$entity,
]);
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
return $object
->access('update', $account, $return_as_object);
}
public function defaultConfiguration() {
return [];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
}