You are here

function entityqueue_entity_field_access in Entityqueue 8

Implements hook_entity_field_access().

File

./entityqueue.module, line 20
Allows users to collect entities in arbitrarily ordered lists.

Code

function entityqueue_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {

  // Only allow edit access on a subqueue title field if the queue doesn't have
  // automated subqueues.
  if ($operation == 'edit' && $field_definition
    ->getName() == 'title' && $items && $items
    ->getEntity()
    ->getEntityTypeId() === 'entity_subqueue') {

    /** @var \Drupal\entityqueue\EntityQueueInterface $queue */
    $queue = $items
      ->getEntity()
      ->getQueue();
    return AccessResult::forbiddenIf($queue
      ->getHandlerPlugin()
      ->hasAutomatedSubqueues());
  }
  return AccessResult::neutral();
}