function course_get_course_object in Course 3.x
Same name and namespace in other branches
- 8.3 course.module \course_get_course_object()
- 8.2 course.module \course_get_course_object()
- 6 course.module \course_get_course_object()
- 7.2 course.module \course_get_course_object()
- 7 course.module \course_get_course_object()
Find a course object by module, type, instance, and optionally course.
If course is provided and an instance exists in two courses, the object returned will be the object in the requested course. If a course is not provided, the object returned will be in the context of the current course.
@todo move to Storage?
Parameters
string $object_type: The object type belonging to the module.
string $instance: The course object instance ID, FROM {course_object}.instance.
Course $course: The Course to pass to the CourseObject instantiation.
Return value
19 calls to course_get_course_object()
- CourseBookEventSubscriber::onRequest in modules/
course_book/ src/ EventSubscriber/ CourseBookEventSubscriber.php - If the current node is a course object, fulfill it for the current user.
- CourseContentEventSubscriber::onRequest in modules/
course_content/ src/ EventSubscriber/ CourseContentEventSubscriber.php - If the current node is a course object, fulfill it for the current user.
- CourseContextTest::testDetermineContext in tests/
src/ Functional/ CourseContextTest.php - Testing finding course and objects via parameter search.
- CourseEventSubscriber::onRequest in src/
EventSubscriber/ CourseEventSubscriber.php - Check if the current node will fulfill an object.
- CourseObjectCommerceTest::testDelayedPayment in modules/
course_commerce/ tests/ src/ Functional/ CourseCommerceTest.php
File
- ./
course.module, line 434 - course.module Core functionality for Courses.
Code
function course_get_course_object(string $object_type, $instance, Course $course = NULL) {
$search = [
'object_type' => $object_type,
'instance' => $instance,
];
if (isset($course)) {
$search['cid'] = $course
->id();
}
$entities = Drupal::entityTypeManager()
->getStorage('course_object')
->loadByProperties($search);
if ($entities) {
return reset($entities);
}
return NULL;
}