You are here

function course_get_course_object in Course 3.x

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

CourseObject

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

... See full list

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;
}