Loading modules/views_bulk_operations_example/src/Plugin/Action/ViewsBulkOperationExampleAction.php +5 −0 Original line number 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 * 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( * id = "views_bulk_operations_example", * label = @Translation("VBO example action"), * type = "", * confirm = TRUE, * api_version = "1", * ) */ class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase implements ViewsBulkOperationsPreconfigurationInterface, PluginFormInterface { Loading src/Action/ViewsBulkOperationsActionCompletedTrait.php +4 −4 Original line number Diff line number Diff line Loading @@ -42,14 +42,14 @@ trait ViewsBulkOperationsActionCompletedTrait { if ($success) { foreach ($results['operations'] as $item) { // Default fallback to maintain backwards compatibility: // if "type" not given, previous message is displayed, // otherwise we display a completely custom one. if (!array_key_exists('type', $item)) { // if api version equals to "1" and type equals to "status", // previous message is displayed, otherwise we display exactly what's // specified in the action. if ($item['type'] === 'status' && $results['api_version'] === '1') { $message = static::translate('Action processing results: @operation (@count).', [ '@operation' => $item['message'], '@count' => $item['count'], ]); $item['type'] = 'status'; } else { $message = new FormattableMarkup('@message (@count)', [ Loading src/Service/ViewsBulkOperationsActionProcessor.php +39 −7 Original line number Diff line number Diff line Loading @@ -461,7 +461,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro $accessResult = $this->action->access($entity, $this->currentUser, TRUE); if ($accessResult->isAllowed() === FALSE) { $result = [ 'message' => $this->t('Access denied'), 'message' => (string) $this->t('Access denied'), 'type' => 'warning', ]; Loading @@ -470,7 +470,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro $reason = $accessResult->getReason(); if (!empty($reason)) { $result = [ 'message' => $this->t('Access denied: @reason', [ 'message' => (string) $this->t('Access denied: @reason', [ '@reason' => $accessResult->getReason(), ]), 'type' => 'warning', Loading Loading @@ -501,6 +501,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro } if (is_array($result) && !($result['message'] instanceof MarkupInterface)) { $deprecated = TRUE; break; } } } Loading @@ -512,7 +513,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro foreach ($results as &$result) { if (!is_array($result)) { $result = [ 'message' => $result, 'message' => (string) $result, ]; } if (!array_key_exists('message', $result)) { Loading @@ -535,6 +536,39 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro 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} */ Loading Loading @@ -564,14 +598,12 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro if (empty($data['list'])) { $data['list'] = $this->getPageList(0); } $batch_results = []; if ($this->populateQueue($data)) { $batch_results = $this->process(); } $results = ['operations' => []]; foreach ($batch_results as $result) { $results['operations'][] = (string) $result; } $results = $this->processResults($batch_results); $data['finished_callback'](TRUE, $results, []); } } Loading src/Service/ViewsBulkOperationsActionProcessorInterface.php +17 −1 Original line number Diff line number Diff line Loading @@ -50,10 +50,26 @@ interface ViewsBulkOperationsActionProcessorInterface { public function populateQueue(array $data, array &$context = []); /** * Process results. * Process queue. * * @return mixed[] * Array of individual results. */ 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. * Loading src/ViewsBulkOperationsBatch.php +2 −19 Original line number Diff line number Diff line Loading @@ -104,25 +104,8 @@ class ViewsBulkOperationsBatch { $count = $actionProcessor->populateQueue($data, $context); $batch_results = $actionProcessor->process(); if (!empty($batch_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['results'] = $actionProcessor->processResults($batch_results, $context['results']); $context['sandbox']['processed'] += $count; $context['sandbox']['page']++; Loading Loading
modules/views_bulk_operations_example/src/Plugin/Action/ViewsBulkOperationExampleAction.php +5 −0 Original line number 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 * 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( * id = "views_bulk_operations_example", * label = @Translation("VBO example action"), * type = "", * confirm = TRUE, * api_version = "1", * ) */ class ViewsBulkOperationExampleAction extends ViewsBulkOperationsActionBase implements ViewsBulkOperationsPreconfigurationInterface, PluginFormInterface { Loading
src/Action/ViewsBulkOperationsActionCompletedTrait.php +4 −4 Original line number Diff line number Diff line Loading @@ -42,14 +42,14 @@ trait ViewsBulkOperationsActionCompletedTrait { if ($success) { foreach ($results['operations'] as $item) { // Default fallback to maintain backwards compatibility: // if "type" not given, previous message is displayed, // otherwise we display a completely custom one. if (!array_key_exists('type', $item)) { // if api version equals to "1" and type equals to "status", // previous message is displayed, otherwise we display exactly what's // specified in the action. if ($item['type'] === 'status' && $results['api_version'] === '1') { $message = static::translate('Action processing results: @operation (@count).', [ '@operation' => $item['message'], '@count' => $item['count'], ]); $item['type'] = 'status'; } else { $message = new FormattableMarkup('@message (@count)', [ Loading
src/Service/ViewsBulkOperationsActionProcessor.php +39 −7 Original line number Diff line number Diff line Loading @@ -461,7 +461,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro $accessResult = $this->action->access($entity, $this->currentUser, TRUE); if ($accessResult->isAllowed() === FALSE) { $result = [ 'message' => $this->t('Access denied'), 'message' => (string) $this->t('Access denied'), 'type' => 'warning', ]; Loading @@ -470,7 +470,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro $reason = $accessResult->getReason(); if (!empty($reason)) { $result = [ 'message' => $this->t('Access denied: @reason', [ 'message' => (string) $this->t('Access denied: @reason', [ '@reason' => $accessResult->getReason(), ]), 'type' => 'warning', Loading Loading @@ -501,6 +501,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro } if (is_array($result) && !($result['message'] instanceof MarkupInterface)) { $deprecated = TRUE; break; } } } Loading @@ -512,7 +513,7 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro foreach ($results as &$result) { if (!is_array($result)) { $result = [ 'message' => $result, 'message' => (string) $result, ]; } if (!array_key_exists('message', $result)) { Loading @@ -535,6 +536,39 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro 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} */ Loading Loading @@ -564,14 +598,12 @@ class ViewsBulkOperationsActionProcessor implements ViewsBulkOperationsActionPro if (empty($data['list'])) { $data['list'] = $this->getPageList(0); } $batch_results = []; if ($this->populateQueue($data)) { $batch_results = $this->process(); } $results = ['operations' => []]; foreach ($batch_results as $result) { $results['operations'][] = (string) $result; } $results = $this->processResults($batch_results); $data['finished_callback'](TRUE, $results, []); } } Loading
src/Service/ViewsBulkOperationsActionProcessorInterface.php +17 −1 Original line number Diff line number Diff line Loading @@ -50,10 +50,26 @@ interface ViewsBulkOperationsActionProcessorInterface { public function populateQueue(array $data, array &$context = []); /** * Process results. * Process queue. * * @return mixed[] * Array of individual results. */ 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. * Loading
src/ViewsBulkOperationsBatch.php +2 −19 Original line number Diff line number Diff line Loading @@ -104,25 +104,8 @@ class ViewsBulkOperationsBatch { $count = $actionProcessor->populateQueue($data, $context); $batch_results = $actionProcessor->process(); if (!empty($batch_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['results'] = $actionProcessor->processResults($batch_results, $context['results']); $context['sandbox']['processed'] += $count; $context['sandbox']['page']++; Loading