annotate core/modules/comment/src/Plugin/Action/PublishComment.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\comment\Plugin\Action;
Chris@0 4
Chris@0 5 use Drupal\Core\Action\ActionBase;
Chris@0 6 use Drupal\Core\Session\AccountInterface;
Chris@0 7
Chris@0 8 /**
Chris@0 9 * Publishes a comment.
Chris@0 10 *
Chris@0 11 * @Action(
Chris@0 12 * id = "comment_publish_action",
Chris@0 13 * label = @Translation("Publish comment"),
Chris@0 14 * type = "comment"
Chris@0 15 * )
Chris@0 16 */
Chris@0 17 class PublishComment extends ActionBase {
Chris@0 18
Chris@0 19 /**
Chris@0 20 * {@inheritdoc}
Chris@0 21 */
Chris@0 22 public function execute($comment = NULL) {
Chris@0 23 $comment->setPublished(TRUE);
Chris@0 24 $comment->save();
Chris@0 25 }
Chris@0 26
Chris@0 27 /**
Chris@0 28 * {@inheritdoc}
Chris@0 29 */
Chris@0 30 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
Chris@0 31 /** @var \Drupal\comment\CommentInterface $object */
Chris@0 32 $result = $object->status->access('edit', $account, TRUE)
Chris@0 33 ->andIf($object->access('update', $account, TRUE));
Chris@0 34
Chris@0 35 return $return_as_object ? $result : $result->isAllowed();
Chris@0 36 }
Chris@0 37
Chris@0 38 }