You are here

public function CourseObject::save in Course 3.x

Same name and namespace in other branches
  1. 8.3 src/Entity/CourseObject.php \Drupal\course\Entity\CourseObject::save()
  2. 8.2 src/Entity/CourseObject.php \Drupal\course\Entity\CourseObject::save()

Apply configuration from session and let objects create their instances before saving the course object.

Overrides EntityBase::save

1 call to CourseObject::save()
CourseObjectBook::save in modules/course_book/src/Plugin/course/CourseObject/CourseObjectBook.php
Override of CourseObjectNode::save()
1 method overrides CourseObject::save()
CourseObjectBook::save in modules/course_book/src/Plugin/course/CourseObject/CourseObjectBook.php
Override of CourseObjectNode::save()

File

src/Entity/CourseObject.php, line 883

Class

CourseObject
Parent abstract base class of all course objects.

Namespace

Drupal\course\Entity

Code

public function save() {

  // If there is no title, set it.
  $this
    ->getTitle();
  if ($ice = $this
    ->getOption('freeze')) {

    // Found frozen data. Restore it to this object.
    $this
      ->setInstanceId($this
      ->thaw($ice));
    $this
      ->setOption('freeze', NULL);
  }

  // Pull temporary configuration from session.
  foreach ($this
    ->optionsDefinition() as $key => $default) {
    $value = $this
      ->getOption($key);
    $this
      ->set($key, $value);
  }

  // If there is no instance ID, tell the object to create external content.
  if (!$this
    ->getInstanceId()) {
    $this
      ->createInstance();
  }

  // Set the ID to NULL because this is a temporary course object being
  // created for the first time.
  if (strpos($this
    ->id(), 'course_object_') !== FALSE) {
    $this
      ->setId(NULL);
  }
  $data = $this
    ->get('data')
    ->getValue();

  // Delegate to parent entity save.
  return parent::save();
}