You are here

public function CourseObjectNode::optionsSubmit in Course 8.2

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

Save object configs to cache.

Overrides CourseObject::optionsSubmit

File

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

Class

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

Namespace

Drupal\course_content\Course\Object

Code

public function optionsSubmit(&$form, FormStateInterface $form_state) {
  if ($form_state
    ->getValue('instance')) {
    $nid = $form_state
      ->getValue('instance');
    if (!is_numeric($nid)) {
      if (preg_match('/^(?:\\s*|(.*) )?\\[\\s*nid\\s*:\\s*(\\d+)\\s*\\]$/', $nid, $matches)) {
        $nid = $matches[2];
      }
    }
    if ($nid) {
      $form_state
        ->setValue('instance', $nid);
    }
    else {

      // Unset it, or we'll erase the relationship (since the textfield is
      // actually blank).
      $form_state
        ->unsetValue('instance');
    }
  }
  parent::optionsSubmit($form, $form_state);
}