You are here

public static function CourseObjectWebform::context in Course 8.3

Same name and namespace in other branches
  1. 8.2 modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php \Drupal\course_webform\Plugin\course\CourseObject\CourseObjectWebform::context()
  2. 3.x modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php \Drupal\course_webform\Plugin\course\CourseObject\CourseObjectWebform::context()

Set the context of which course this course object belongs to.

The return parameters should be compliant with course_determine_context().

Overrides CourseObject::context

File

modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php, line 151

Class

CourseObjectWebform
Plugin annotation @CourseObject( id = "webform", label = "Webform", handlers = { "fulfillment" = "\Drupal\course_webform\Plugin\course\CourseObject\CourseObjectWebformFulfillment" } )

Namespace

Drupal\course_webform\Plugin\course\CourseObject

Code

public static function context() {
  $route_match = Drupal::routeMatch();
  if ($route_match
    ->getRouteName() == 'entity.webform.canonical') {
    $webform = $route_match
      ->getParameter('webform');
    if ($courseObject = course_get_course_object('webform', $webform
      ->id())) {
      return array(
        'object_type' => 'webform',
        'instance' => $webform
          ->id(),
      );
    }
  }
}