Implements hook_ENTITY_TYPE_create_access() for entity type "paragraph".
function paragraphs_type_permissions_paragraph_create_access(AccountInterface $account = NULL, array $context = array(), $entity_bundle = NULL) {
$permissions =& drupal_static(__FUNCTION__, array());
// Set static cache id to use the type machine name.
$type = $entity_bundle;
$op = 'create';
// If we've already checked access for this type, user and op, return from
// cache.
if (isset($permissions[$account
->id()][$type][$op])) {
return $permissions[$account
->id()][$type][$op];
}
// If the current user has access to this type/op, return access allowed,
// forbidden otherwise.
if ($account
->hasPermission('bypass paragraphs type content access') || $account
->hasPermission($op . ' paragraph content ' . $type)) {
$permissions[$account
->id()][$type][$op] = AccessResult::allowed()
->cachePerPermissions();
}
else {
$permissions[$account
->id()][$type][$op] = AccessResult::forbidden()
->cachePerPermissions();
}
return $permissions[$account
->id()][$type][$op];
}