ConfirmAction.php in Views Bulk Operations (VBO) 8
File
src/Form/ConfirmAction.php
View source
<?php
namespace Drupal\views_bulk_operations\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager;
use Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessorInterface;
class ConfirmAction extends FormBase {
use ViewsBulkOperationsFormTrait;
protected $tempStoreFactory;
protected $actionManager;
protected $actionProcessor;
public function __construct(PrivateTempStoreFactory $tempStoreFactory, ViewsBulkOperationsActionManager $actionManager, ViewsBulkOperationsActionProcessorInterface $actionProcessor) {
$this->tempStoreFactory = $tempStoreFactory;
$this->actionManager = $actionManager;
$this->actionProcessor = $actionProcessor;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('user.private_tempstore'), $container
->get('plugin.manager.views_bulk_operations_action'), $container
->get('views_bulk_operations.processor'));
}
public function getFormId() {
return 'views_bulk_operations_confirm_action';
}
public function buildForm(array $form, FormStateInterface $form_state, $view_id = NULL, $display_id = NULL) {
$form_data = $this
->getFormData($view_id, $display_id);
if (!isset($form_data['action_id'])) {
return;
}
$form_state
->setStorage($form_data);
if (!empty($form_data['entity_labels'])) {
$form['list'] = [
'#theme' => 'item_list',
'#items' => $form_data['entity_labels'],
];
}
$form['#title'] = $this
->formatPlural($form_data['selected_count'], 'Are you sure you wish to perform "%action" action on 1 entity?', 'Are you sure you wish to perform "%action" action on %count entities?', [
'%action' => $form_data['action_label'],
'%count' => $form_data['selected_count'],
]);
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Execute action'),
'#submit' => [
[
$this,
'submitForm',
],
],
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_data = $form_state
->getStorage();
$this->tempStoreFactory
->get($form_data['tempstore_name'])
->delete($this
->currentUser()
->id());
$this->actionProcessor
->executeProcessing($form_data);
$form_state
->setRedirectUrl($form_data['redirect_url']);
}
}