BlockTypeAccessControlHandler.php

Same filename in other branches
  1. 10 core/modules/block_content/src/BlockTypeAccessControlHandler.php

Namespace

Drupal\block_content

File

core/modules/block_content/src/BlockTypeAccessControlHandler.php

View source
<?php

namespace Drupal\block_content;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Defines the access control handler for the "Block Type" entity type.
 *
 * @see \Drupal\block_content\Entity\BlockContentType
 */
class BlockTypeAccessControlHandler extends EntityAccessControlHandler {
    
    /**
     * {@inheritdoc}
     */
    protected $viewLabelOperation = TRUE;
    
    /**
     * {@inheritdoc}
     */
    protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
        if ($operation === 'view label') {
            return AccessResult::allowedIfHasPermission($account, 'access block library')->orIf(parent::checkAccess($entity, $operation, $account));
        }
        return parent::checkAccess($entity, $operation, $account);
    }

}

Classes

Title Deprecated Summary
BlockTypeAccessControlHandler Defines the access control handler for the "Block Type" entity type.

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