UnpublishAction.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/Action/Plugin/Action/UnpublishAction.php
  2. 8.9.x core/lib/Drupal/Core/Action/Plugin/Action/UnpublishAction.php
  3. 10 core/lib/Drupal/Core/Action/Plugin/Action/UnpublishAction.php

Namespace

Drupal\Core\Action\Plugin\Action

File

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

View source
<?php

namespace Drupal\Core\Action\Plugin\Action;

use Drupal\Core\Action\Plugin\Action\Derivative\EntityPublishedActionDeriver;
use Drupal\Core\Action\Attribute\Action;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Unpublishes an entity.
 */
class UnpublishAction extends EntityActionBase {
    
    /**
     * {@inheritdoc}
     */
    public function execute($entity = NULL) {
        $entity->setUnpublished()
            ->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
UnpublishAction Unpublishes an entity.

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