You are here

NodeMakePostPublic.php in Private 8

File

src/Plugin/Action/NodeMakePostPublic.php
View source
<?php

namespace Drupal\private_content\Plugin\Action;

use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;

/**
 * Make a post public.
 *
 * @Action(
 *   id = "node_make_content_public",
 *   label = @Translation("Make content public"),
 *   type = "node"
 * )
 */
class NodeMakePostPublic extends ActionBase {

  /**
   * {@inheritdoc}
   */
  public function execute($entity = NULL) {
    $entity->private->value = 0;
    $entity
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {

    /** @var \Drupal\node\NodeInterface $object */
    $result = $object
      ->access('update', $account, TRUE)
      ->andIf($object->status
      ->access('edit', $account, TRUE));
    return $return_as_object ? $result : $result
      ->isAllowed();
  }

}

Classes

Namesort descending Description
NodeMakePostPublic Make a post public.