function LayoutBuilderHooks::blockContentAccess

Implements hook_ENTITY_TYPE_access().

File

core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php, line 263

Class

LayoutBuilderHooks
Hook implementations for layout_builder.

Namespace

Drupal\layout_builder\Hook

Code

public function blockContentAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    
    /** @var \Drupal\block_content\BlockContentInterface $entity */
    if ($operation === 'view' || $entity->isReusable() || empty(\Drupal::service('inline_block.usage')->getUsage($entity->id()))) {
        // If the operation is 'view' or this is reusable block or if this is
        // non-reusable that isn't used by this module then don't alter the access.
        return AccessResult::neutral();
    }
    if ($account->hasPermission('create and edit custom blocks')) {
        return AccessResult::allowed();
    }
    return AccessResult::forbidden();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.