You are here

class ConfirmAction in Views Bulk Operations (VBO) 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Form/ConfirmAction.php \Drupal\views_bulk_operations\Form\ConfirmAction
  2. 8 src/Form/ConfirmAction.php \Drupal\views_bulk_operations\Form\ConfirmAction
  3. 8.2 src/Form/ConfirmAction.php \Drupal\views_bulk_operations\Form\ConfirmAction

Default action execution confirmation form.

Hierarchy

Expanded class hierarchy of ConfirmAction

1 string reference to 'ConfirmAction'
views_bulk_operations.routing.yml in ./views_bulk_operations.routing.yml
views_bulk_operations.routing.yml

File

src/Form/ConfirmAction.php, line 15

Namespace

Drupal\views_bulk_operations\Form
View source
class ConfirmAction extends FormBase {
  use ViewsBulkOperationsFormTrait;

  /**
   * The tempstore service.
   *
   * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
   */
  protected $tempStoreFactory;

  /**
   * Views Bulk Operations action manager.
   *
   * @var \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager
   */
  protected $actionManager;

  /**
   * Views Bulk Operations action processor.
   *
   * @var \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessorInterface
   */
  protected $actionProcessor;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempStoreFactory
   *   User private temporary storage factory.
   * @param \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager $actionManager
   *   Extended action manager object.
   * @param \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessorInterface $actionProcessor
   *   Views Bulk Operations action processor.
   */
  public function __construct(PrivateTempStoreFactory $tempStoreFactory, ViewsBulkOperationsActionManager $actionManager, ViewsBulkOperationsActionProcessorInterface $actionProcessor) {
    $this->tempStoreFactory = $tempStoreFactory;
    $this->actionManager = $actionManager;
    $this->actionProcessor = $actionProcessor;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('tempstore.private'), $container
      ->get('plugin.manager.views_bulk_operations_action'), $container
      ->get('views_bulk_operations.processor'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'views_bulk_operations_confirm_action';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $view_id = NULL, $display_id = NULL) {
    $form_data = $this
      ->getFormData($view_id, $display_id);

    // TODO: display an error msg, redirect back.
    if (!isset($form_data['action_id'])) {
      return;
    }
    $form['list'] = $this
      ->getListRenderable($form_data);
    $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',
        ],
      ],
    ];
    $this
      ->addCancelButton($form);
    $form_state
      ->set('views_bulk_operations', $form_data);
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_data = $form_state
      ->get('views_bulk_operations');
    $this
      ->deleteTempstoreData($form_data['view_id'], $form_data['display_id']);
    $this->actionProcessor
      ->executeProcessing($form_data);
    $form_state
      ->setRedirectUrl($form_data['redirect_url']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfirmAction::$actionManager protected property Views Bulk Operations action manager.
ConfirmAction::$actionProcessor protected property Views Bulk Operations action processor.
ConfirmAction::$tempStoreFactory protected property The tempstore service.
ConfirmAction::buildForm public function Form constructor. Overrides FormInterface::buildForm
ConfirmAction::create public static function Instantiates a new instance of this class. Overrides FormBase::create
ConfirmAction::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
ConfirmAction::submitForm public function Form submission handler. Overrides FormInterface::submitForm
ConfirmAction::__construct public function Constructor.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
ViewsBulkOperationsFormTrait::$tempStoreName protected property The tempstore name.
ViewsBulkOperationsFormTrait::$viewTempstore protected property The tempstore object associated with the current view.
ViewsBulkOperationsFormTrait::addCancelButton protected function Add a cancel button into a VBO form.
ViewsBulkOperationsFormTrait::addListData protected function Add data needed for entity list rendering.
ViewsBulkOperationsFormTrait::calculateEntityBulkFormKey public static function Calculates the bulk form key for an entity.
ViewsBulkOperationsFormTrait::cancelForm public function Submit callback to cancel an action and return to the view.
ViewsBulkOperationsFormTrait::deleteTempstoreData protected function Deletes the current view user tempstore data.
ViewsBulkOperationsFormTrait::getFormData protected function Helper function to prepare data needed for proper form display.
ViewsBulkOperationsFormTrait::getListItem protected function Get an entity list item from a bulk form key.
ViewsBulkOperationsFormTrait::getListRenderable protected function Build selected entities list renderable.
ViewsBulkOperationsFormTrait::getMultipageList protected function Build the selection info element.
ViewsBulkOperationsFormTrait::getSelectionInfoTitle protected function Get the selection info title.
ViewsBulkOperationsFormTrait::getTempstore protected function Initialize the current view tempstore object.
ViewsBulkOperationsFormTrait::getTempstoreData protected function Gets the current view user tempstore data.
ViewsBulkOperationsFormTrait::setTempstoreData protected function Sets the current view user tempstore data.