public function UnpinContentAction::execute in moderated content bulk publish 1.0.x
Same name and namespace in other branches
- 8 src/Plugin/Action/UnpinContentAction.php \Drupal\moderated_content_bulk_publish\Plugin\Action\UnpinContentAction::execute()
- 2.0.x src/Plugin/Action/UnpinContentAction.php \Drupal\moderated_content_bulk_publish\Plugin\Action\UnpinContentAction::execute()
Executes the plugin.
Overrides ExecutableInterface::execute
File
- src/
Plugin/ Action/ UnpinContentAction.php, line 35
Class
Namespace
Drupal\moderated_content_bulk_publish\Plugin\ActionCode
public function execute($entity = NULL) {
/*
* All config resides in $this->configuration.
* Passed view rows will be available in $this->context.
* Data about the view used to select results and optionally
* the batch context are available in $this->context or externally
* through the public getContext() method.
* The entire ViewExecutable object with selected result
* rows is available in $this->view or externally through
* the public getView() method.
*/
// Do some processing..
// ...
//\Drupal::Messenger()->addStatus(utf8_encode('Pin bulk operation by moderated_content_bulk_publish module'));
$user = \Drupal::currentUser();
if ($user
->hasPermission('moderated content bulk unpin content')) {
\Drupal::logger('moderated_content_bulk_publish')
->notice("EXECUTING PIN CONTENT FOR " . $entity
->label());
$adminPin = new AdminPin($entity, $entity
->isSticky());
$entity = $adminPin
->unpin();
// Check if unpinned
if ($entity
->isSticky()) {
$msg = "Something went wrong, the entity must be unpinned by this point.";
\Drupal::Messenger()
->addError(utf8_encode($msg));
\Drupal::logger('moderated_content_bulk_publish')
->warning($msg);
return $msg;
}
return sprintf('Example action (configuration: %s)', print_r($this->configuration, TRUE));
}
else {
\Drupal::messenger()
->addWarning(t("You don't have access to execute this operation!"));
return;
}
}