MerciConfigureAction.php in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2
File
modules/merci_line_item/src/Form/MerciConfigureAction.php
View source
<?php
namespace Drupal\merci_line_item\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;
use Drupal\views_bulk_operations\Form\ViewsBulkOperationsFormTrait;
use Drupal\views_bulk_operations\Form\ConfigureAction;
class MerciConfigureAction extends ConfigureAction {
public function buildForm(array $form, FormStateInterface $form_state, $view_id = NULL, $display_id = NULL) {
$form = parent::buildForm($form, $form_state, $view_id, $display_id);
$form['actions']['cancel']['#submit'][] = [
$this,
'cancelFormData',
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_data = $form_state
->get('views_bulk_operations');
$action = $this->actionManager
->createInstance($form_data['action_id']);
if (method_exists($action, 'submitConfigurationForm')) {
$action
->submitConfigurationForm($form, $form_state);
$form_data['configuration'] = $action
->getConfiguration();
}
else {
$form_state
->cleanValues();
$form_data['configuration'] = $form_state
->getValues();
}
if ($form_state
->isRebuilding()) {
return;
}
$definition = $this->actionManager
->getDefinition($form_data['action_id']);
if (!empty($definition['confirm_form_route_name'])) {
$this
->setTempstoreData($form_data, $form_data['view_id'], $form_data['display_id']);
$form_state
->setRedirect($definition['confirm_form_route_name'], [
'view_id' => $form_data['view_id'],
'display_id' => $form_data['display_id'],
]);
}
else {
$this
->deleteTempstoreData($form_data['view_id'], $form_data['display_id']);
$this->actionProcessor
->executeProcessing($form_data);
$form_state
->setRedirectUrl($form_data['redirect_url']);
}
}
public function cancelFormData(array &$form, FormStateInterface $form_state) {
$form_data = $form_state
->get('views_bulk_operations');
$this
->getTempstore($form_data['view_id'], $form_data['display_id'])
->delete('validation_errors');
}
}