You are here

function _quick_node_clone_has_clone_permission in Quick Node Clone 8

Determine if the current user has permission to clone a specified node.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $node: The node to examine.

Return value

bool TRUE or FALSE

2 calls to _quick_node_clone_has_clone_permission()
QuickNodeCloneNodeAccess::cloneNode in src/Controller/QuickNodeCloneNodeAccess.php
Limit access to the clone according to their restricted state.
quick_node_clone_entity_operation in ./quick_node_clone.module
Implements hook_entity_operation().

File

./quick_node_clone.module, line 82
Contains quick_node_clone.module.

Code

function _quick_node_clone_has_clone_permission(ContentEntityInterface $node) {
  $current_user = \Drupal::currentUser();
  $bundle = $node
    ->bundle();
  if ($current_user
    ->hasPermission("clone {$bundle} content")) {
    if (\Drupal::moduleHandler()
      ->moduleExists('gnode')) {
      $group_contents = GroupContent::loadByEntity($node);
      foreach ($group_contents as $group_content) {

        // We check via createEntityAccess() for "create group entity", not via
        // createAccess() for "relate existing entity to group", as we do in
        // fact create a new entity.
        // @see \Drupal\group\Access\GroupContentCreateAnyEntityAccessCheck::access
        // @todo Use group access control handler when we can rely on group 1.0.
        $access = $group_content
          ->getContentPlugin()
          ->createEntityAccess($group_content
          ->getGroup(), $current_user);
        if ($access) {
          return TRUE;
        }
      }
    }

    // Only check global access if we there is no group module enabled, or
    // content does not have group(s).
    if (empty($group_contents)) {
      if ($node
        ->access('create')) {
        return TRUE;
      }
    }
  }
  return FALSE;
}