Newer
Older
Angie Byron
committed
<?php
namespace Drupal\node\Access;
use Drupal\Core\Entity\EntityTypeManagerInterface;
Angie Byron
committed
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
/**
* Determines access to node previews.
*
* @ingroup node_access
Angie Byron
committed
*/
class NodePreviewAccessCheck implements AccessInterface {
/**
* The entity type manager service.
Angie Byron
committed
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
Angie Byron
committed
*/
protected $entityTypeManager;
Angie Byron
committed
/**
* Constructs an EntityCreateAccessCheck object.
Angie Byron
committed
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
Angie Byron
committed
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
Angie Byron
committed
}
/**
* 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.
*
Lee Rowlands
committed
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
Angie Byron
committed
*/
public function access(AccountInterface $account, NodeInterface $node_preview) {
if ($node_preview->isNew()) {
$access_controller = $this->entityTypeManager->getAccessControlHandler('node');
catch
committed
return $access_controller->createAccess($node_preview->bundle(), $account, [], TRUE);
Angie Byron
committed
}
else {
catch
committed
return $node_preview->access('update', $account, TRUE);