You are here

class UnpublishAction in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Action/Plugin/Action/UnpublishAction.php \Drupal\Core\Action\Plugin\Action\UnpublishAction
  2. 9 core/lib/Drupal/Core/Action/Plugin/Action/UnpublishAction.php \Drupal\Core\Action\Plugin\Action\UnpublishAction

Unpublishes an entity.

Plugin annotation


@Action(
  id = "entity:unpublish_action",
  action_label = @Translation("Unpublish"),
  deriver = "Drupal\Core\Action\Plugin\Action\Derivative\EntityPublishedActionDeriver",
)

Hierarchy

  • class \Drupal\Core\Action\Plugin\Action\UnpublishAction extends \Drupal\Core\Action\Plugin\Action\EntityActionBase

Expanded class hierarchy of UnpublishAction

2 files declare their use of UnpublishAction
content_moderation.module in core/modules/content_moderation/content_moderation.module
Contains content_moderation.module.
ModerationOptOutUnpublish.php in core/modules/content_moderation/src/Plugin/Action/ModerationOptOutUnpublish.php

File

core/lib/Drupal/Core/Action/Plugin/Action/UnpublishAction.php, line 16

Namespace

Drupal\Core\Action\Plugin\Action
View source
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();
  }

}

Members