-
Notifications
You must be signed in to change notification settings - Fork 11
/
paragraphs.api.php
54 lines (46 loc) · 1.63 KB
/
paragraphs.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* @file
* Hooks provided by the Paragraphs module.
*/
/**
* Check whether a user may perform the operation on the paragraphs item.
*
* @param ParagraphsItemEntity $entity
* Entity to check the access against.
* @param string $op
* The operation to be performed on the paragraphs item. Possible values are:
* - "view"
* - "update"
* - "delete"
* - "create".
* @param object $account
* Optional, a user object representing the user for whom the operation is to
* be performed. Determines access for a user other than the current user.
*
* @return bool
* TRUE if the operation may be performed, FALSE otherwise.
*/
function hook_paragraphs_item_access(ParagraphsItemEntity $entity, $op, $account) {
$permissions = &backdrop_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($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];
}