function paragraphs_bundle_permissions_paragraphs_item_access in Paragraphs 7
Implements hook_paragraphs_item_access().
File
- modules/
paragraphs_bundle_permissions/ paragraphs_bundle_permissions.module, line 11 - Add view / create / update / delete permissions for all paragraph bundles.
Code
function paragraphs_bundle_permissions_paragraphs_item_access($entity, $op, $account) {
$permissions =& drupal_static(__FUNCTION__, array());
if (!in_array($op, array(
'view',
'update',
'delete',
'create',
), TRUE) || $entity === NULL) {
// If there is no bundle to check against, or the $op is not one of the
// supported ones, we return access ignore.
return PARAGRAPHS_ITEM_ACCESS_IGNORE;
}
$bundle = $entity->bundle;
// Set static cache id to use the bundle machine name.
$cid = $bundle;
// If we've already checked access for this bundle, user and op, return from
// cache.
if (isset($permissions[$account->uid][$cid][$op])) {
return $permissions[$account->uid][$cid][$op];
}
if (user_access('bypass paragraphs bundle content access', $account) || user_access($op . ' paragraph content ' . $bundle, $account)) {
$permissions[$account->uid][$cid][$op] = PARAGRAPHS_ITEM_ACCESS_ALLOW;
}
else {
$permissions[$account->uid][$cid][$op] = PARAGRAPHS_ITEM_ACCESS_DENY;
}
return $permissions[$account->uid][$cid][$op];
}