You are here

public function CourseObjectAccessGrade::optionsValidate in Course 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/course/CourseObjectAccess/CourseObjectAccessGrade.php \Drupal\course\Plugin\course\CourseObjectAccess\CourseObjectAccessGrade::optionsValidate()
  2. 3.x src/Plugin/course/CourseObjectAccess/CourseObjectAccessGrade.php \Drupal\course\Plugin\course\CourseObjectAccess\CourseObjectAccessGrade::optionsValidate()

Overrides CourseObjectAccessPluginBase::optionsValidate

File

src/Plugin/course/CourseObjectAccess/CourseObjectAccessGrade.php, line 28

Class

CourseObjectAccessGrade
Plugin annotation @CourseObjectAccess( id = "grade", label = @Translation("Grade"), )

Namespace

Drupal\course\Plugin\course\CourseObjectAccess

Code

public function optionsValidate($form, &$form_state) {
  if (!empty($form_state['course_grade_range']['low']) || !empty($form_state['course_grade_range']['high'])) {

    // If user filled out at least one.
    if (is_numeric($form_state['course_grade_range']['low']) && is_numeric($form_state['course_grade_range']['high'])) {

      // User filled out both.
      if ($form_state['course_grade_range']['low'] > $form_state['course_grade_range']['high']) {
        form_error($form['course_grade_range'], t('High range cannot be lower than the low range.'));
      }
    }
    else {

      // User did not fill out both.
      form_error($form['course_grade_range'], t('You must enter a numeric value for both the low and high grade range.'));
    }
  }
}