function hook_course_access in Course 3.x
Same name and namespace in other branches
- 8.3 course.api.php \hook_course_access()
- 8.2 course.api.php \hook_course_access()
- 7.2 course.api.php \hook_course_access()
- 7 course.api.php \hook_course_access()
Allow modules to determine if this course should be restricted.
If any module implementing this hook returns FALSE or an array containing 'success' => FALSE, the course will be restricted.
Parameters
string $op: Either 'enroll' or 'take'.
object $node: The course node.
object $user: The user who may or may not enroll/take the course.
Return value
boolean|array Either FALSE, or an array containing:
- success: Boolean. Indicates whether or not the user has permission to enroll or take this course.
- message: String. If success is FALSE, a message to display to the user.
3 functions implement hook_course_access()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- course_commerce_course_access in modules/
course_commerce/ course_commerce.module - Implements hook_course_access().
- course_course_access in ./
course.module - Implements hook_course_access().
- course_uc_course_access in modules/
course_uc/ course_uc.module - Implements hook_course_access().
3 invocations of hook_course_access()
- Course::accessMultiple in src/
Entity/ Course.php - Get all access results.
- course_commerce_form_alter in modules/
course_commerce/ course_commerce.module - Implements hook_form_alter().
- course_uc_form_alter in modules/
course_uc/ course_uc.module - Implements hook_form_alter().
File
- ./
course.api.php, line 107 - Hooks provided by Course module.
Code
function hook_course_access(Course $entity, $operation, AccountInterface $account) {
if ($op == 'take') {
// Example: do not allow users to take courses on Wednesdays.
if (date('L') == 'wednesday') {
$hooks['course_notopen'] = AccessResult::forbidden('Courses are closed on Wednesdays.');
}
elseif (date('m') == 12 && date('d') == 25) {
$hooks['course_notopen'] = AccessResult::allowed();
}
return $hooks;
}
if ($op == 'enroll') {
// Same usage as $op == 'take'.
}
}