function EntityAccessControlHandler::buildCreateAccessCid

Builds the create access result cache ID.

If there is no context other than langcode and entity type id, then the cache id can be simply the bundle. Otherwise, a custom implementation is needed to ensure cacheability, and the default implementation here returns null.

Parameters

array $context: The create access context.

string|null $entity_bundle: The entity bundle, if the entity type has bundles.

Return value

string|null The create access result cache ID, or null if uncacheable.

2 calls to EntityAccessControlHandler::buildCreateAccessCid()
EntityAccessControlHandler::createAccess in core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php
Checks access to create an entity.
EntityTestAccessControlHandler::buildCreateAccessCid in core/modules/system/tests/modules/entity_test/src/EntityTestAccessControlHandler.php
Builds the create access result cache ID.
1 method overrides EntityAccessControlHandler::buildCreateAccessCid()
EntityTestAccessControlHandler::buildCreateAccessCid in core/modules/system/tests/modules/entity_test/src/EntityTestAccessControlHandler.php
Builds the create access result cache ID.

File

core/lib/Drupal/Core/Entity/EntityAccessControlHandler.php, line 422

Class

EntityAccessControlHandler
Defines a default implementation for entity access control handler.

Namespace

Drupal\Core\Entity

Code

protected function buildCreateAccessCid(array $context, ?string $entity_bundle) : ?string {
    $extendedContext = array_filter($context, function ($key) {
        return !in_array($key, [
            'entity_type_id',
            'langcode',
        ]);
    }, ARRAY_FILTER_USE_KEY);
    if (empty($extendedContext)) {
        return $entity_bundle ? 'create:' . $entity_bundle : 'create';
    }
    return NULL;
}

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