Loading modules/views_bulk_operations_example/src/Plugin/Action/ViewsBulkOperationExampleAction.php +5 −0 Original line number Original line Diff line number Diff line Loading @@ -15,11 +15,16 @@ use Drupal\views_bulk_operations\Action\ViewsBulkOperationsPreconfigurationInter * If type is left empty, action will be selectable for all * If type is left empty, action will be selectable for all * entity types. * entity types. * * * The api_version annotation parameter specifies the behaviour of displayed * messages: anything other than "1" displays counts of exactly what's returned * by the action execute() and executeMultiple() method. * * @Action( * @Action( * id = "views_bulk_operations_example", * id = "views_bulk_operations_example", * label = @Translation("VBO example action"), * label = @Translation("VBO example action"), * type = "", * type = "", * confirm = TRUE, * confirm = TRUE, * api_version = "1", * ) * ) */ */ class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase implements ViewsBulkOperationsPreconfigurationInterface, PluginFormInterface { class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase implements ViewsBulkOperationsPreconfigurationInterface, PluginFormInterface { Loading src/Action/ViewsBulkOperationsActionCompletedTrait.php +4 −4 Original line number Original line Diff line number Diff line Loading @@ -42,14 +42,14 @@ trait ViewsBulkOperationsActionCompletedTrait { if ($success) { if ($success) { foreach ($results['operations'] as $item) { foreach ($results['operations'] as $item) { // Default fallback to maintain backwards compatibility: // Default fallback to maintain backwards compatibility: // if "type" not given, previous message is displayed, // if api version equals to "1" and type equals to "status", // otherwise we display a completely custom one. // previous message is displayed, otherwise we display exactly what's if (!array_key_exists('type', $item)) { // specified in the action. if ($item['type'] === 'status' && $results['api_version'] === '1') { $message = static::translate('Action processing results: @operation (@count).', [ $message = static::translate('Action processing results: @operation (@count).', [ '@operation' => $item['message'], '@operation' => $item['message'], '@count' => $item['count'], '@count' => $item['count'], ]); ]); $item['type'] = 'status'; } } else { else { $message = new FormattableMarkup('@message (@count)', [ $message = new FormattableMarkup('@message (@count)', [ Loading src/Service/ViewsBulkOperationsActionProcessor.php +39 −7 Original line number Original line Diff line number Diff line Loading @@ -461,7 +461,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro $accessResult = $this->action->access($entity, $this->currentUser, TRUE); $accessResult = $this->action->access($entity, $this->currentUser, TRUE); if ($accessResult->isAllowed() === FALSE) { if ($accessResult->isAllowed() === FALSE) { $result = [ $result = [ 'message' => $this->t('Access denied'), 'message' => (string) $this->t('Access denied'), 'type' => 'warning', 'type' => 'warning', ]; ]; Loading @@ -470,7 +470,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro $reason = $accessResult->getReason(); $reason = $accessResult->getReason(); if (!empty($reason)) { if (!empty($reason)) { $result = [ $result = [ 'message' => $this->t('Access denied: @reason', [ 'message' => (string) $this->t('Access denied: @reason', [ '@reason' => $accessResult->getReason(), '@reason' => $accessResult->getReason(), ]), ]), 'type' => 'warning', 'type' => 'warning', Loading Loading @@ -501,6 +501,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro } } if (is_array($result) && !($result['message'] instanceof MarkupInterface)) { if (is_array($result) && !($result['message'] instanceof MarkupInterface)) { $deprecated = TRUE; $deprecated = TRUE; break; } } } } } } Loading @@ -512,7 +513,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro foreach ($results as &$result) { foreach ($results as &$result) { if (!is_array($result)) { if (!is_array($result)) { $result = [ $result = [ 'message' => $result, 'message' => (string) $result, ]; ]; } } if (!array_key_exists('message', $result)) { if (!array_key_exists('message', $result)) { Loading @@ -535,6 +536,39 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro return array_merge($output, $results); return array_merge($output, $results); } } /** * {@inheritdoc} */ public function processResults(array $results, array $previous = []) { $output['operations'] = array_key_exists('operations', $previous) ? $previous['operations'] : []; // Set the API version. $action_definition = $this->action->getPluginDefinition(); $output['api_version'] = array_key_exists('api_version', $action_definition) ? $action_definition['api_version'] : '1'; foreach ($results as $result) { if (!array_key_exists('type', $result)) { $result['type'] = 'status'; } $found_delta = NULL; foreach ($output['operations'] as $delta => $item) { if ($item['message'] === $result['message'] && $item['type'] === $result['type']) { $found_delta = $delta; break; } } if ($found_delta !== NULL) { $output['operations'][$found_delta]['count']++; } else { $result['count'] = 1; $output['operations'][] = $result; } } return $output; } /** /** * {@inheritdoc} * {@inheritdoc} */ */ Loading Loading @@ -564,14 +598,12 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro if (empty($data['list'])) { if (empty($data['list'])) { $data['list'] = $this->getPageList(0); $data['list'] = $this->getPageList(0); } } $batch_results = []; if ($this->populateQueue($data)) { if ($this->populateQueue($data)) { $batch_results = $this->process(); $batch_results = $this->process(); } } $results = ['operations' => []]; $results = $this->processResults($batch_results); foreach ($batch_results as $result) { $results['operations'][] = (string) $result; } $data['finished_callback'](TRUE, $results, []); $data['finished_callback'](TRUE, $results, []); } } } } Loading src/Service/ViewsBulkOperationsActionProcessorInterface.php +17 −1 Original line number Original line Diff line number Diff line Loading @@ -50,10 +50,26 @@ interface ViewsBulkOperationsActionProcessorInterface { public function populateQueue(array $data, array &$context = []); public function populateQueue(array $data, array &$context = []); /** /** * Process results. * Process queue. * * @return mixed[] * Array of individual results. */ */ public function process(); public function process(); /** * Process results. * * Merges multiple individual operation results into one or more containing * counts. * * @param mixed[] $results * Individual results array. * @param mixed[] $previous * Results from previous batches. */ public function processResults(array $results, array $previous = []); /** /** * Helper function for processing results from view data. * Helper function for processing results from view data. * * Loading src/ViewsBulkOperationsBatch.php +2 −19 Original line number Original line Diff line number Diff line Loading @@ -104,25 +104,8 @@ class ViewsBulkOperationsBatch { $count = $actionProcessor->populateQueue($data, $context); $count = $actionProcessor->populateQueue($data, $context); $batch_results = $actionProcessor->process(); $batch_results = $actionProcessor->process(); if (!empty($batch_results)) { $context['results'] = $actionProcessor->processResults($batch_results, $context['results']); foreach ($batch_results as $result) { $message = $result['message']; $found_delta = NULL; foreach ($context['results']['operations'] as $delta => $item) { if ($item['message'] === $result['message'] && $item['type'] === $result['type']) { $found_delta = $delta; break; } } if ($found_delta !== NULL) { $context['results']['operations'][$found_delta]['count']++; } else { $result['count'] = 1; $context['results']['operations'][] = $result; } } } $context['sandbox']['processed'] += $count; $context['sandbox']['processed'] += $count; $context['sandbox']['page']++; $context['sandbox']['page']++; Loading Loading
modules/views_bulk_operations_example/src/Plugin/Action/ViewsBulkOperationExampleAction.php +5 −0 Original line number Original line Diff line number Diff line Loading @@ -15,11 +15,16 @@ use Drupal\views_bulk_operations\Action\ViewsBulkOperationsPreconfigurationInter * If type is left empty, action will be selectable for all * If type is left empty, action will be selectable for all * entity types. * entity types. * * * The api_version annotation parameter specifies the behaviour of displayed * messages: anything other than "1" displays counts of exactly what's returned * by the action execute() and executeMultiple() method. * * @Action( * @Action( * id = "views_bulk_operations_example", * id = "views_bulk_operations_example", * label = @Translation("VBO example action"), * label = @Translation("VBO example action"), * type = "", * type = "", * confirm = TRUE, * confirm = TRUE, * api_version = "1", * ) * ) */ */ class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase implements ViewsBulkOperationsPreconfigurationInterface, PluginFormInterface { class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase implements ViewsBulkOperationsPreconfigurationInterface, PluginFormInterface { Loading
src/Action/ViewsBulkOperationsActionCompletedTrait.php +4 −4 Original line number Original line Diff line number Diff line Loading @@ -42,14 +42,14 @@ trait ViewsBulkOperationsActionCompletedTrait { if ($success) { if ($success) { foreach ($results['operations'] as $item) { foreach ($results['operations'] as $item) { // Default fallback to maintain backwards compatibility: // Default fallback to maintain backwards compatibility: // if "type" not given, previous message is displayed, // if api version equals to "1" and type equals to "status", // otherwise we display a completely custom one. // previous message is displayed, otherwise we display exactly what's if (!array_key_exists('type', $item)) { // specified in the action. if ($item['type'] === 'status' && $results['api_version'] === '1') { $message = static::translate('Action processing results: @operation (@count).', [ $message = static::translate('Action processing results: @operation (@count).', [ '@operation' => $item['message'], '@operation' => $item['message'], '@count' => $item['count'], '@count' => $item['count'], ]); ]); $item['type'] = 'status'; } } else { else { $message = new FormattableMarkup('@message (@count)', [ $message = new FormattableMarkup('@message (@count)', [ Loading
src/Service/ViewsBulkOperationsActionProcessor.php +39 −7 Original line number Original line Diff line number Diff line Loading @@ -461,7 +461,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro $accessResult = $this->action->access($entity, $this->currentUser, TRUE); $accessResult = $this->action->access($entity, $this->currentUser, TRUE); if ($accessResult->isAllowed() === FALSE) { if ($accessResult->isAllowed() === FALSE) { $result = [ $result = [ 'message' => $this->t('Access denied'), 'message' => (string) $this->t('Access denied'), 'type' => 'warning', 'type' => 'warning', ]; ]; Loading @@ -470,7 +470,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro $reason = $accessResult->getReason(); $reason = $accessResult->getReason(); if (!empty($reason)) { if (!empty($reason)) { $result = [ $result = [ 'message' => $this->t('Access denied: @reason', [ 'message' => (string) $this->t('Access denied: @reason', [ '@reason' => $accessResult->getReason(), '@reason' => $accessResult->getReason(), ]), ]), 'type' => 'warning', 'type' => 'warning', Loading Loading @@ -501,6 +501,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro } } if (is_array($result) && !($result['message'] instanceof MarkupInterface)) { if (is_array($result) && !($result['message'] instanceof MarkupInterface)) { $deprecated = TRUE; $deprecated = TRUE; break; } } } } } } Loading @@ -512,7 +513,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro foreach ($results as &$result) { foreach ($results as &$result) { if (!is_array($result)) { if (!is_array($result)) { $result = [ $result = [ 'message' => $result, 'message' => (string) $result, ]; ]; } } if (!array_key_exists('message', $result)) { if (!array_key_exists('message', $result)) { Loading @@ -535,6 +536,39 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro return array_merge($output, $results); return array_merge($output, $results); } } /** * {@inheritdoc} */ public function processResults(array $results, array $previous = []) { $output['operations'] = array_key_exists('operations', $previous) ? $previous['operations'] : []; // Set the API version. $action_definition = $this->action->getPluginDefinition(); $output['api_version'] = array_key_exists('api_version', $action_definition) ? $action_definition['api_version'] : '1'; foreach ($results as $result) { if (!array_key_exists('type', $result)) { $result['type'] = 'status'; } $found_delta = NULL; foreach ($output['operations'] as $delta => $item) { if ($item['message'] === $result['message'] && $item['type'] === $result['type']) { $found_delta = $delta; break; } } if ($found_delta !== NULL) { $output['operations'][$found_delta]['count']++; } else { $result['count'] = 1; $output['operations'][] = $result; } } return $output; } /** /** * {@inheritdoc} * {@inheritdoc} */ */ Loading Loading @@ -564,14 +598,12 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro if (empty($data['list'])) { if (empty($data['list'])) { $data['list'] = $this->getPageList(0); $data['list'] = $this->getPageList(0); } } $batch_results = []; if ($this->populateQueue($data)) { if ($this->populateQueue($data)) { $batch_results = $this->process(); $batch_results = $this->process(); } } $results = ['operations' => []]; $results = $this->processResults($batch_results); foreach ($batch_results as $result) { $results['operations'][] = (string) $result; } $data['finished_callback'](TRUE, $results, []); $data['finished_callback'](TRUE, $results, []); } } } } Loading
src/Service/ViewsBulkOperationsActionProcessorInterface.php +17 −1 Original line number Original line Diff line number Diff line Loading @@ -50,10 +50,26 @@ interface ViewsBulkOperationsActionProcessorInterface { public function populateQueue(array $data, array &$context = []); public function populateQueue(array $data, array &$context = []); /** /** * Process results. * Process queue. * * @return mixed[] * Array of individual results. */ */ public function process(); public function process(); /** * Process results. * * Merges multiple individual operation results into one or more containing * counts. * * @param mixed[] $results * Individual results array. * @param mixed[] $previous * Results from previous batches. */ public function processResults(array $results, array $previous = []); /** /** * Helper function for processing results from view data. * Helper function for processing results from view data. * * Loading
src/ViewsBulkOperationsBatch.php +2 −19 Original line number Original line Diff line number Diff line Loading @@ -104,25 +104,8 @@ class ViewsBulkOperationsBatch { $count = $actionProcessor->populateQueue($data, $context); $count = $actionProcessor->populateQueue($data, $context); $batch_results = $actionProcessor->process(); $batch_results = $actionProcessor->process(); if (!empty($batch_results)) { $context['results'] = $actionProcessor->processResults($batch_results, $context['results']); foreach ($batch_results as $result) { $message = $result['message']; $found_delta = NULL; foreach ($context['results']['operations'] as $delta => $item) { if ($item['message'] === $result['message'] && $item['type'] === $result['type']) { $found_delta = $delta; break; } } if ($found_delta !== NULL) { $context['results']['operations'][$found_delta]['count']++; } else { $result['count'] = 1; $context['results']['operations'][] = $result; } } } $context['sandbox']['processed'] += $count; $context['sandbox']['processed'] += $count; $context['sandbox']['page']++; $context['sandbox']['page']++; Loading