You are here

function course_get_course_object in Course 8.2

Same name and namespace in other branches
  1. 8.3 course.module \course_get_course_object()
  2. 6 course.module \course_get_course_object()
  3. 7.2 course.module \course_get_course_object()
  4. 7 course.module \course_get_course_object()
  5. 3.x 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

mixed $module: The module name of this course object, or an array resembling a row in the {course_object} table.

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

CourseObject

17 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.
CourseContextTestCase::testDetermineContext in tests/src/Functional/CourseContextTestCase.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.
CourseObjectManualTestCase::testCourseObjectManual in modules/course_object_manual/tests/src/Functional/CourseObjectManualTestCase.php
Test manual course object functionality.

... See full list

File

./course.module, line 440
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;
}