You are here

public static function WorkflowManager::isOwner in Workflow 8

Determine if User is owner/author of the entity.

Parameters

\Drupal\Core\Session\AccountInterface $account:

\Drupal\Core\Entity\EntityInterface $entity:

Return value

bool

Overrides WorkflowManagerInterface::isOwner

4 calls to WorkflowManager::isOwner()
WorkflowAccessControlHandler::access in src/WorkflowAccessControlHandler.php
Checks access to an operation on a given entity or entity translation.
WorkflowHistoryAccess::access in src/Access/WorkflowHistoryAccess.php
Check if the user has permissions to view this workflow.
WorkflowState::getTransitions in src/Entity/WorkflowState.php
Returns the allowed transitions for the current state.
WorkflowTransition::isAllowed in src/Entity/WorkflowTransition.php
Determines if the current transition between 2 states is allowed.

File

src/Entity/WorkflowManager.php, line 433

Class

WorkflowManager
Manages entity type plugin definitions.

Namespace

Drupal\workflow\Entity

Code

public static function isOwner(AccountInterface $account, EntityInterface $entity = NULL) {
  $is_owner = FALSE;
  $entity_id = $entity ? $entity
    ->id() : '';
  if (!$entity_id) {

    // This is a new entity. User is author. Add 'author' role to user.
    $is_owner = TRUE;
    return $is_owner;
  }
  $uid = $account ? $account
    ->id() : -1;

  // Some entities (e.g., taxonomy_term) do not have a uid.
  // $entity_uid = $entity->get('uid'); // isset($entity->uid) ? $entity->uid : 0;
  $entity_uid = method_exists($entity, 'getOwnerId') ? $entity
    ->getOwnerId() : -1;
  if ($entity_uid > 0 && $uid > 0 && $entity_uid == $uid) {

    // This is an existing entity. User is author.
    // D8: use "access own" permission. D7: Add 'author' role to user.
    // N.B.: If 'anonymous' is the author, don't allow access to History Tab,
    // since anyone can access it, and it will be published in Search engines.
    $is_owner = TRUE;
  }
  else {

    // This is an existing entity. User is not the author. Do nothing.
  }
  return $is_owner;
}