You are here

function CourseObjectAttendance::optionsValidate in Course 3.x

Check code uniqueness.

Overrides CourseObject::optionsValidate

File

modules/course_attendance/src/Plugin/course/CourseObject/CourseObjectAttendance.php, line 111

Class

CourseObjectAttendance
Plugin annotation @CourseObject( id = "attendance", label = "Attendance", )

Namespace

Drupal\course_attendance\Plugin\course\CourseObject

Code

function optionsValidate(&$form, FormStateInterface $form_state) {
  parent::optionsValidate($form, $form_state);
  if ($courseObject = $this
    ->findObjectByCode($form_state
    ->getValue('instance'))) {
    if ($courseObject
      ->id() != $this
      ->id()) {
      $form_state
        ->setError($form['attendance']['instance'], t('Code is already in use.'));
    }
  }

  /* @var $duration \Drupal\duration_field\Service\DurationService */
  $duration = \Drupal::service('duration_field.service');
  $form_state
    ->setValue('open', $form_state
    ->getValue('open_direction') * $duration
    ->getSecondsFromDateInterval($form_state
    ->getValue('open')));
  $form_state
    ->setValue('close', $form_state
    ->getValue('close_direction') * $duration
    ->getSecondsFromDateInterval($form_state
    ->getValue('close')));
}