PublishAction.php in Drupal 9
File
core/lib/Drupal/Core/Action/Plugin/Action/PublishAction.php
View source
<?php
namespace Drupal\Core\Action\Plugin\Action;
use Drupal\Core\Session\AccountInterface;
class PublishAction extends EntityActionBase {
public function execute($entity = NULL) {
$entity
->setPublished()
->save();
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$key = $object
->getEntityType()
->getKey('published');
$result = $object
->access('update', $account, TRUE)
->andIf($object->{$key}
->access('edit', $account, TRUE));
return $return_as_object ? $result : $result
->isAllowed();
}
}