Version 1
[yaffs-website] / web / core / modules / node / src / Plugin / Action / StickyNode.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  * Makes a node sticky.
10  *
11  * @Action(
12  *   id = "node_make_sticky_action",
13  *   label = @Translation("Make selected content sticky"),
14  *   type = "node"
15  * )
16  */
17 class StickyNode extends ActionBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function execute($entity = NULL) {
23     $entity->setSticky(TRUE)->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->sticky->access('edit', $account, TRUE));
33     return $return_as_object ? $access : $access->isAllowed();
34   }
35
36 }