ec6209d9b756fdea604923f1cd7ca68bb9a838cb
[yaffs-website] / web / core / modules / node / src / Plugin / Action / UnpublishNode.php
1 <?php
2
3 namespace Drupal\node\Plugin\Action;
4
5 use Drupal\Core\Action\ActionBase;
6 use Drupal\Core\Session\AccountInterface;
7
8 /**
9  * Unpublishes a node.
10  *
11  * @Action(
12  *   id = "node_unpublish_action",
13  *   label = @Translation("Unpublish selected content"),
14  *   type = "node"
15  * )
16  */
17 class UnpublishNode extends ActionBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function execute($entity = NULL) {
23     $entity->setUnpublished()->save();
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
30     /** @var \Drupal\node\NodeInterface $object */
31     $access = $object->access('update', $account, TRUE)
32       ->andIf($object->status->access('edit', $account, TRUE));
33
34     return $return_as_object ? $access : $access->isAllowed();
35   }
36
37 }