04644a90246640353a142378d6921076a41d86c0
[yaffs-website] / web / core / modules / node / src / Plugin / Action / DemoteNode.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  * Demotes a node.
10  *
11  * @Action(
12  *   id = "node_unpromote_action",
13  *   label = @Translation("Demote selected content from front page"),
14  *   type = "node"
15  * )
16  */
17 class DemoteNode extends ActionBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function execute($entity = NULL) {
23     $entity->setPromoted(FALSE);
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     $result = $object->access('update', $account, TRUE)
33       ->andIf($object->promote->access('edit', $account, TRUE));
34
35     return $return_as_object ? $result : $result->isAllowed();
36   }
37
38 }