class ViewsBulkOperationsController in Views Bulk Operations (VBO) 4.0.x
Same name and namespace in other branches
- 8.3 src/Controller/ViewsBulkOperationsController.php \Drupal\views_bulk_operations\Controller\ViewsBulkOperationsController
- 8 src/Controller/ViewsBulkOperationsController.php \Drupal\views_bulk_operations\Controller\ViewsBulkOperationsController
- 8.2 src/Controller/ViewsBulkOperationsController.php \Drupal\views_bulk_operations\Controller\ViewsBulkOperationsController
Defines VBO controller class.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\views_bulk_operations\Controller\ViewsBulkOperationsController implements ContainerInjectionInterface uses ViewsBulkOperationsFormTrait
Expanded class hierarchy of ViewsBulkOperationsController
File
- src/
Controller/ ViewsBulkOperationsController.php, line 20
Namespace
Drupal\views_bulk_operations\ControllerView source
class ViewsBulkOperationsController extends ControllerBase implements ContainerInjectionInterface {
use ViewsBulkOperationsFormTrait;
/**
* The tempstore service.
*
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
*/
protected $tempStoreFactory;
/**
* Views Bulk Operations action processor.
*
* @var \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessorInterface
*/
protected $actionProcessor;
/**
* The Renderer service object.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a new controller object.
*
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempStoreFactory
* Private temporary storage factory.
* @param \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessorInterface $actionProcessor
* Views Bulk Operations action processor.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The Renderer service object.
*/
public function __construct(PrivateTempStoreFactory $tempStoreFactory, ViewsBulkOperationsActionProcessorInterface $actionProcessor, RendererInterface $renderer) {
$this->tempStoreFactory = $tempStoreFactory;
$this->actionProcessor = $actionProcessor;
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('tempstore.private'), $container
->get('views_bulk_operations.processor'), $container
->get('renderer'));
}
/**
* The actual page callback.
*
* @param string $view_id
* The current view ID.
* @param string $display_id
* The display ID of the current view.
*/
public function execute($view_id, $display_id) {
$view_data = $this
->getTempstoreData($view_id, $display_id);
if (empty($view_data)) {
throw new NotFoundHttpException();
}
$this
->deleteTempstoreData();
$this->actionProcessor
->executeProcessing($view_data);
if ($view_data['batch']) {
return batch_process($view_data['redirect_url']);
}
else {
return new RedirectResponse($view_data['redirect_url']
->setAbsolute()
->toString());
}
}
/**
* AJAX callback to update selection (multipage).
*
* @param string $view_id
* The current view ID.
* @param string $display_id
* The display ID of the current view.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*/
public function updateSelection($view_id, $display_id, Request $request) {
$response = [];
$tempstore_data = $this
->getTempstoreData($view_id, $display_id);
if (empty($tempstore_data)) {
throw new NotFoundHttpException();
}
$list = $request->request
->get('list');
$op = $request->request
->get('op', 'check');
// Reverse operation when in exclude mode.
if (!empty($tempstore_data['exclude_mode'])) {
if ($op === 'add') {
$op = 'remove';
}
elseif ($op === 'remove') {
$op = 'add';
}
}
switch ($op) {
case 'add':
foreach ($list as $bulkFormKey) {
if (!isset($tempstore_data['list'][$bulkFormKey])) {
$tempstore_data['list'][$bulkFormKey] = $this
->getListItem($bulkFormKey);
}
}
break;
case 'remove':
foreach ($list as $bulkFormKey) {
if (isset($tempstore_data['list'][$bulkFormKey])) {
unset($tempstore_data['list'][$bulkFormKey]);
}
}
break;
case 'method_include':
unset($tempstore_data['exclude_mode']);
$tempstore_data['list'] = [];
break;
case 'method_exclude':
$tempstore_data['exclude_mode'] = TRUE;
$tempstore_data['list'] = [];
break;
}
$this
->setTempstoreData($tempstore_data);
$count = empty($tempstore_data['exclude_mode']) ? count($tempstore_data['list']) : $tempstore_data['total_results'] - count($tempstore_data['list']);
$selection_info_renderable = $this
->getMultipageList($tempstore_data);
$response_data = [
'count' => $count,
'selection_info' => $this->renderer
->renderRoot($selection_info_renderable),
];
$response = new AjaxResponse();
$response
->setData($response_data);
return $response;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function | Returns a redirect response object for the specified route. | |
ControllerBase:: |
protected | function | Returns the state storage service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
ViewsBulkOperationsController:: |
protected | property | Views Bulk Operations action processor. | |
ViewsBulkOperationsController:: |
protected | property | The Renderer service object. | |
ViewsBulkOperationsController:: |
protected | property | The tempstore service. | |
ViewsBulkOperationsController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
ViewsBulkOperationsController:: |
public | function | The actual page callback. | |
ViewsBulkOperationsController:: |
public | function | AJAX callback to update selection (multipage). | |
ViewsBulkOperationsController:: |
public | function | Constructs a new controller object. | |
ViewsBulkOperationsFormTrait:: |
protected | property | The tempstore name. | |
ViewsBulkOperationsFormTrait:: |
protected | property | The tempstore object associated with the current view. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Add a cancel button into a VBO form. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Add data needed for entity list rendering. | |
ViewsBulkOperationsFormTrait:: |
public static | function | Calculates the bulk form key for an entity. | |
ViewsBulkOperationsFormTrait:: |
public | function | Submit callback to cancel an action and return to the view. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Deletes the current view user tempstore data. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Helper function to prepare data needed for proper form display. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Get an entity list item from a bulk form key. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Build selected entities list renderable. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Build the selection info element. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Get the selection info title. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Initialize the current view tempstore object. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Gets the current view user tempstore data. | |
ViewsBulkOperationsFormTrait:: |
protected | function | Sets the current view user tempstore data. |