public function PublishContentAccess::access in Publish Content 8
File
- src/
Access/ PublishContentAccess.php, line 40
Class
- PublishContentAccess
- Access class checking the permissions for publishing and unpublishing.
Namespace
Drupal\publishcontent\AccessCode
public function access(AccountInterface $account, NodeInterface $node) {
$this->account = $account;
$this->node = $node;
$this->arguments = [
'@type' => $node
->bundle(),
];
$langcode = $node
->language()
->getId();
// We don't want to show the action if the translation doesn't even exist.
if ($node
->isTranslatable() && !$node
->hasTranslation($langcode)) {
return AccessResult::forbidden();
}
$action = $node
->isPublished() ? 'unpublish' : 'publish';
if ($action == 'publish' && ($this
->accessPublishAny() || $this
->accessPublishEditable() || $this
->accessPublishAnyType() || $this
->accessPublishOwnType() || $this
->accessPublishEditableType()) || $action == 'unpublish' && ($this
->accessUnpublishAny() || $this
->accessUnpublishEditable() || $this
->accessUnpublishAnyType() || $this
->accessUnpublishOwnType() || $this
->accessUnpublishEditableType())) {
return AccessResult::allowed();
}
return AccessResult::forbidden();
}