function course_content_node_access in Course 3.x
Same name and namespace in other branches
- 8.3 modules/course_content/course_content.module \course_content_node_access()
- 8.2 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 42
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 AccessResult::allowed()
->setCacheMaxAge(0);
}
else {
// Deny access, make sure it is not cached.
return AccessResult::forbidden()
->setCacheMaxAge(0);
}
}
}
}