public function PinContentAction::execute in moderated content bulk publish 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Action/PinContentAction.php \Drupal\moderated_content_bulk_publish\Plugin\Action\PinContentAction::execute()
- 1.0.x src/Plugin/Action/PinContentAction.php \Drupal\moderated_content_bulk_publish\Plugin\Action\PinContentAction::execute()
Executes the plugin.
Overrides ExecutableInterface::execute
File
- src/
Plugin/ Action/ PinContentAction.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 pin content')) {
\Drupal::logger('moderated_content_bulk_publish')
->notice("EXECUTING PIN CONTENT FOR " . $entity
->label());
$adminPin = new AdminPin($entity, $entity
->isSticky());
$entity = $adminPin
->pin();
// Check if pinned
if (!$entity
->isSticky()) {
$msg = "Something went wrong, the entity must be pinned 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;
}
}