You are here

public function CourseObjectWebform::createInstance 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::createInstance()
  2. 3.x modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php \Drupal\course_webform\Plugin\course\CourseObject\CourseObjectWebform::createInstance()

Creates a course object.

For example, this would create the new node and return the node ID if this was a CourseObjectNode.

Do not confuse this with save(), which saves the course outline record for tracking.

Course objects should call setInstanceId() if this is a course object that creates external resources.

Overrides CourseObject::createInstance

File

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

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 function createInstance() {
  $webform = Webform::create([
    'id' => 'course_object_' . $this
      ->id(),
  ]);
  $webform
    ->save();
  $this
    ->setInstanceId($webform
    ->id());
}