function layout_builder_block_content_access

Same name in other branches
  1. 8.9.x core/modules/layout_builder/layout_builder.module \layout_builder_block_content_access()
  2. 10 core/modules/layout_builder/layout_builder.module \layout_builder_block_content_access()

Implements hook_ENTITY_TYPE_access().

File

core/modules/layout_builder/layout_builder.module, line 252

Code

function layout_builder_block_content_access(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.