You are here

public function CourseObjectNode::createInstance in Course 3.x

Same name and namespace in other branches
  1. 8.3 modules/course_content/src/Course/Object/CourseObjectNode.php \Drupal\course_content\Course\Object\CourseObjectNode::createInstance()
  2. 8.2 modules/course_content/src/Course/Object/CourseObjectNode.php \Drupal\course_content\Course\Object\CourseObjectNode::createInstance()

Create a node and set it as this course object's node.

Parameters

stdClass $node: A node to be processed for creation, or none to create a generic node. If a node is provided, it must have at least a type.

Overrides CourseObject::createInstance

1 call to CourseObjectNode::createInstance()
CourseObjectBook::createInstance in modules/course_book/src/Plugin/course/CourseObject/CourseObjectBook.php
Make the book.
1 method overrides CourseObjectNode::createInstance()
CourseObjectBook::createInstance in modules/course_book/src/Plugin/course/CourseObject/CourseObjectBook.php
Make the book.

File

modules/course_content/src/Course/Object/CourseObjectNode.php, line 126

Class

CourseObjectNode
A course object that uses a node as a base.

Namespace

Drupal\course_content\Course\Object

Code

public function createInstance($node = NULL) {
  if (!$node) {
    $node = Node::create([
      'type' => $this
        ->getOption('node_type'),
    ]);
  }
  $node->title = $this
    ->getTitle();
  $node->uid = Drupal::currentUser()
    ->id();
  $node
    ->save();
  $this
    ->setInstanceId($node
    ->id());
}