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