Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / node_access.twig
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 }