public function CourseObjectWebform::createInstance in Course 3.x
Same name and namespace in other branches
- 8.3 modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php \Drupal\course_webform\Plugin\course\CourseObject\CourseObjectWebform::createInstance()
- 8.2 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\CourseObjectCode
public function createInstance() {
$webform = Webform::create([
'id' => 'course_object_' . uniqid(),
'title' => $this
->getTitle(),
'uid' => \Drupal::currentUser()
->id(),
]);
$webform
->save();
$this
->setInstanceId($webform
->id());
}