097c34147f52b842cc7cd22c6ff8ec182789891c
[yaffs-website] / PromoteNode.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  * Promotes a node.
10  *
11  * @Action(
12  *   id = "node_promote_action",
13  *   label = @Translation("Promote selected content to front page"),
14  *   type = "node"
15  * )
16  */
17 class PromoteNode extends ActionBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function execute($entity = NULL) {
23     $entity->setPromoted(TRUE);
24     $entity->save();
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
31     /** @var \Drupal\node\NodeInterface $object */
32     $access = $object->access('update', $account, TRUE)
33       ->andif($object->promote->access('edit', $account, TRUE));
34     return $return_as_object ? $access : $access->isAllowed();
35   }
36
37 }