Mercurial > hg > cmmr2012-drupal-site
comparison vendor/chi-teck/drupal-code-generator/templates/d8/hook/node_access.twig @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 /** | |
2 * Implements hook_node_access(). | |
3 */ | |
4 function {{ machine_name }}_node_access(\Drupal\node\NodeInterface $node, $op, \Drupal\Core\Session\AccountInterface $account) { | |
5 $type = $node->bundle(); | |
6 | |
7 switch ($op) { | |
8 case 'create': | |
9 return AccessResult::allowedIfHasPermission($account, 'create ' . $type . ' content'); | |
10 | |
11 case 'update': | |
12 if ($account->hasPermission('edit any ' . $type . ' content', $account)) { | |
13 return AccessResult::allowed()->cachePerPermissions(); | |
14 } | |
15 else { | |
16 return AccessResult::allowedIf($account->hasPermission('edit own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerPermissions()->cachePerUser()->addCacheableDependency($node); | |
17 } | |
18 | |
19 case 'delete': | |
20 if ($account->hasPermission('delete any ' . $type . ' content', $account)) { | |
21 return AccessResult::allowed()->cachePerPermissions(); | |
22 } | |
23 else { | |
24 return AccessResult::allowedIf($account->hasPermission('delete own ' . $type . ' content', $account) && ($account->id() == $node->getOwnerId()))->cachePerPermissions()->cachePerUser()->addCacheableDependency($node); | |
25 } | |
26 | |
27 default: | |
28 // No opinion. | |
29 return AccessResult::neutral(); | |
30 } | |
31 } |