Mercurial > hg > cmmr2012-drupal-site
diff core/modules/node/src/Access/NodePreviewAccessCheck.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | 12f9dff5fda9 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/node/src/Access/NodePreviewAccessCheck.php Thu Jul 05 14:24:15 2018 +0000 @@ -0,0 +1,55 @@ +<?php + +namespace Drupal\node\Access; + +use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Routing\Access\AccessInterface; +use Drupal\Core\Session\AccountInterface; +use Drupal\node\NodeInterface; + +/** + * Determines access to node previews. + * + * @ingroup node_access + */ +class NodePreviewAccessCheck implements AccessInterface { + + /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManagerInterface + */ + protected $entityManager; + + /** + * Constructs a EntityCreateAccessCheck object. + * + * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * The entity manager. + */ + public function __construct(EntityManagerInterface $entity_manager) { + $this->entityManager = $entity_manager; + } + + /** + * Checks access to the node preview page. + * + * @param \Drupal\Core\Session\AccountInterface $account + * The currently logged in account. + * @param \Drupal\node\NodeInterface $node_preview + * The node that is being previewed. + * + * @return string + * A \Drupal\Core\Access\AccessInterface constant value. + */ + public function access(AccountInterface $account, NodeInterface $node_preview) { + if ($node_preview->isNew()) { + $access_controller = $this->entityManager->getAccessControlHandler('node'); + return $access_controller->createAccess($node_preview->bundle(), $account, [], TRUE); + } + else { + return $node_preview->access('update', $account, TRUE); + } + } + +}