c8d3b5bfa39474af2f5cb0d4790d2fadb39a3018
[yaffs-website] / web / core / modules / node / src / Plugin / Action / PublishNode.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  * Publishes a node.
10  *
11  * @Action(
12  *   id = "node_publish_action",
13  *   label = @Translation("Publish selected content"),
14  *   type = "node"
15  * )
16  */
17 class PublishNode extends ActionBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function execute($entity = NULL) {
23     $entity->setPublished()->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     $result = $object->access('update', $account, TRUE)
32       ->andIf($object->status->access('edit', $account, TRUE));
33
34     return $return_as_object ? $result : $result->isAllowed();
35   }
36
37 }