function course_content_node_access in Course 8.3
Same name and namespace in other branches
- 8.2 modules/course_content/course_content.module \course_content_node_access()
- 3.x modules/course_content/course_content.module \course_content_node_access()
Implements hook_node_access().
Check node access.
File
- modules/
course_content/ course_content.module, line 41
Code
function course_content_node_access(NodeInterface $node, $op, $account) {
if ($op == 'view') {
if (($courseObject = course_get_course_object('content', $node
->id())) && $courseObject
->getOption('private')) {
// This object is inside of a course and the object is private.
if ($courseObject
->getFulfillment($account)
->id()) {
// The user can take the object, so grant access. Make sure it is not
// cached in case of a revocation.
return \Drupal\Core\Access\AccessResult::allowed()
->setCacheMaxAge(0);
}
else {
// Deny access, make sure it is not cached.
return \Drupal\Core\Access\AccessResult::forbidden()
->setCacheMaxAge(0);
}
}
}
}