You are here

protected function LinkCheckerLinkAccessControlHandler::checkFieldAccess in Link checker 8

Default field access as determined by this access control handler.

Parameters

string $operation: The operation access should be checked for. Usually one of "view" or "edit".

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

\Drupal\Core\Session\AccountInterface $account: The user session for which to check access.

\Drupal\Core\Field\FieldItemListInterface $items: (optional) The field values for which to check access, or NULL if access is checked for the field definition, without any specific value available. Defaults to NULL.

Return value

\Drupal\Core\Access\AccessResultInterface The access result.

Overrides EntityAccessControlHandler::checkFieldAccess

File

src/LinkCheckerLinkAccessControlHandler.php, line 37

Class

LinkCheckerLinkAccessControlHandler
Defines the access control handler for the linkchecker link entity type.

Namespace

Drupal\linkchecker

Code

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

  // No user can change read only fields.
  if ($operation == 'edit') {
    switch ($field_definition
      ->getName()) {
      case 'method':
      case 'status':
        return AccessResult::allowedIfHasPermissions($account, [
          'administer linkchecker',
          'edit linkchecker link settings',
        ], 'OR');
      default:
        return AccessResult::forbidden();
    }
  }

  // User not allowed to view URL field if he does not have access to parent
  // entity.
  if ($operation == 'view' && isset($items) && $field_definition
    ->getName() == 'url') {
    return $this
      ->checkParentEntityAccess($items
      ->getEntity(), $operation, $account);
  }
  return parent::checkFieldAccess($operation, $field_definition, $account, $items);
}