PublishAction.php

Same filename and directory in other branches
  1. 8.9.x core/lib/Drupal/Core/Action/Plugin/Action/PublishAction.php
  2. 10 core/lib/Drupal/Core/Action/Plugin/Action/PublishAction.php
  3. 11.x core/lib/Drupal/Core/Action/Plugin/Action/PublishAction.php

Namespace

Drupal\Core\Action\Plugin\Action

File

core/lib/Drupal/Core/Action/Plugin/Action/PublishAction.php

View source
<?php

namespace Drupal\Core\Action\Plugin\Action;

use Drupal\Core\Session\AccountInterface;

/**
 * Publishes an entity.
 *
 * @Action(
 *   id = "entity:publish_action",
 *   action_label = @Translation("Publish"),
 *   deriver = "Drupal\Core\Action\Plugin\Action\Derivative\EntityPublishedActionDeriver",
 * )
 */
class PublishAction extends EntityActionBase {
    
    /**
     * {@inheritdoc}
     */
    public function execute($entity = NULL) {
        $entity->setPublished()
            ->save();
    }
    
    /**
     * {@inheritdoc}
     */
    public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
        $key = $object->getEntityType()
            ->getKey('published');
        
        /** @var \Drupal\Core\Entity\EntityInterface $object */
        $result = $object->access('update', $account, TRUE)
            ->andIf($object->{$key}
            ->access('edit', $account, TRUE));
        return $return_as_object ? $result : $result->isAllowed();
    }

}

Classes

Title Deprecated Summary
PublishAction Publishes an entity.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.