You are here

public function ViewsBulkOperationsAdvancedTestAction::execute in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsAdvancedTestAction.php \Drupal\views_bulk_operations_test\Plugin\Action\ViewsBulkOperationsAdvancedTestAction::execute()
  2. 8.2 tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsAdvancedTestAction.php \Drupal\views_bulk_operations_test\Plugin\Action\ViewsBulkOperationsAdvancedTestAction::execute()
  3. 4.0.x tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsAdvancedTestAction.php \Drupal\views_bulk_operations_test\Plugin\Action\ViewsBulkOperationsAdvancedTestAction::execute()

Executes the plugin.

Overrides ExecutableInterface::execute

File

tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsAdvancedTestAction.php, line 32

Class

ViewsBulkOperationsAdvancedTestAction
Action for test purposes only.

Namespace

Drupal\views_bulk_operations_test\Plugin\Action

Code

public function execute($entity = NULL) {

  // Check if $this->view is an instance of ViewsExecutable.
  if (!$this->view instanceof ViewExecutable) {
    throw new \Exception('View passed to action object is not an instance of \\Drupal\\views\\ViewExecutable.');
  }

  // Check if context array has been passed to the action.
  if (empty($this->context)) {
    throw new \Exception('Context array empty in action object.');
  }
  drupal_set_message(sprintf('Test action (preconfig: %s, config: %s, label: %s)', $this->configuration['test_preconfig'], $this->configuration['test_config'], $entity
    ->label()));

  // Unpublish entity.
  if ($this->configuration['test_config'] === 'unpublish') {
    $entity->status = NODE_NOT_PUBLISHED;
    $entity
      ->save();
  }
  return 'Test';
}