You are here

protected function GeneralEntityReferenceFormatter::checkAccess in Formatter Suite 8

Checks access to the given entity.

By default, entity 'view' access is checked. However, a subclass can choose to exclude certain items from entity access checking by immediately granting access.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to check.

Return value

\Drupal\Core\Access\AccessResult A cacheable access result.

Overrides EntityReferenceFormatterBase::checkAccess

File

src/Plugin/Field/FieldFormatter/GeneralEntityReferenceFormatter.php, line 934

Class

GeneralEntityReferenceFormatter
Formats an entity reference as one or more links.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

protected function checkAccess(EntityInterface $entity) {
  switch ($this
    ->getSetting('entityReferenceStyle')) {
    case 'id':
      return AccessResult::allowed();
    default:

      // Make sure we have access to the title.
      return $entity
        ->access('view label', NULL, TRUE);
  }
}