You are here

public function CourseObjectNode::optionsValidate in Course 8.3

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

Validate the options form. Check the node type.

Overrides CourseObject::optionsValidate

File

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

Class

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

Namespace

Drupal\course_content\Course\Object

Code

public function optionsValidate(&$form, FormStateInterface $form_state) {
  parent::optionsValidate($form, $form_state);
  $nid = $form_state
    ->getValues()['instance'];
  if (empty($nid) && isset($form_state
    ->getValues()['node_type']) && empty($form_state
    ->getValues()['node_type'])) {
    $form_state
      ->setErrorByName('node_type', t('Please select a node type.'));
  }
  $missing_node = !preg_match('/^(?:\\s*|(.*) )?\\[\\s*nid\\s*:\\s*(\\d+)\\s*\\]$/', $nid);
  if (($form_state
    ->getValues()['use_existing_node'] || !$this
    ->isTemporary()) && $missing_node) {
    $form_state
      ->setErrorByName('instance', t('Please select a node.'));
  }
}