public function ViewsBulkOperationsAdvancedTestAction::execute in Views Bulk Operations (VBO) 4.0.x
Same name and namespace in other branches
- 8.3 tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsAdvancedTestAction.php \Drupal\views_bulk_operations_test\Plugin\Action\ViewsBulkOperationsAdvancedTestAction::execute()
- 8 tests/views_bulk_operations_test/src/Plugin/Action/ViewsBulkOperationsAdvancedTestAction.php \Drupal\views_bulk_operations_test\Plugin\Action\ViewsBulkOperationsAdvancedTestAction::execute()
- 8.2 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 33
Class
- ViewsBulkOperationsAdvancedTestAction
- Action for test purposes only.
Namespace
Drupal\views_bulk_operations_test\Plugin\ActionCode
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.');
}
$this
->messenger()
->addMessage(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') {
if (!$entity
->isDefaultTranslation()) {
$entity = \Drupal::service('entity_type.manager')
->getStorage('node')
->load($entity
->id());
}
$entity
->setUnpublished();
$entity
->save();
}
return 'Test';
}