You are here

function CourseObjectQuiz::createInstance in Course 3.x

Same name and namespace in other branches
  1. 8.3 modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php \Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuiz::createInstance()
  2. 8.2 modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php \Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuiz::createInstance()

Create the quiz node and set it as this object's instance.

Overrides CourseObject::createInstance

File

modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php, line 50

Class

CourseObjectQuiz
Plugin annotation @CourseObject( id = "quiz", label = "Quiz", handlers = { "fulfillment" = "\Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuizFulfillment" } )

Namespace

Drupal\course_quiz\Plugin\course\CourseObject

Code

function createInstance() {
  $quiz = Quiz::create([
    'title' => $this
      ->getTitle(),
    'type' => 'quiz',
  ]);
  $quiz
    ->save();
  $this
    ->setInstanceId($quiz
    ->id());
}