Skip to content

Commit

Permalink
MDL-39167 quiz access rules: need to validate their settings.
Browse files Browse the repository at this point in the history
We were missing the hook in the form validation method. We had them
everywhere else they were needed.
  • Loading branch information
timhunt committed Apr 17, 2013
1 parent b3661ab commit d823a63
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mod/quiz/accessmanager.php
Expand Up @@ -123,6 +123,24 @@ public static function get_browser_security_choices() {
return $options;
}

/**
* Validate the data from any form fields added using {@link add_settings_form_fields()}.
* @param array $errors the errors found so far.
* @param array $data the submitted form data.
* @param array $files information about any uploaded files.
* @param mod_quiz_mod_form $quizform the quiz form object.
* @return array $errors the updated $errors array.
*/
public static function validate_settings_form_fields(array $errors,
array $data, $files, mod_quiz_mod_form $this) {

foreach (self::get_rule_classes() as $rule) {
$errors = $rule::validate_settings_form_fields($errors, $data, $files, $this);
}

return $errors;
}

/**
* Save any submitted settings when the quiz settings form is submitted.
*
Expand Down
14 changes: 14 additions & 0 deletions mod/quiz/accessrule/accessrulebase.php
Expand Up @@ -256,6 +256,20 @@ public static function add_settings_form_fields(
// By default do nothing.
}

/**
* Validate the data from any form fields added using {@link add_settings_form_fields()}.
* @param array $errors the errors found so far.
* @param array $data the submitted form data.
* @param array $files information about any uploaded files.
* @param mod_quiz_mod_form $quizform the quiz form object.
* @return array $errors the updated $errors array.
*/
public static function validate_settings_form_fields(array $errors,
array $data, $files, mod_quiz_mod_form $quizform) {

return $errors;
}

/**
* @return array key => lang string any choices to add to the quiz Browser
* security settings menu.
Expand Down
3 changes: 3 additions & 0 deletions mod/quiz/mod_form.php
Expand Up @@ -575,6 +575,9 @@ public function validation($data, $files) {
}
}

// Any other rule plugins.
$errors = quiz_access_manager::validate_settings_form_fields($errors, $data, $files, $this);

return $errors;
}
}

0 comments on commit d823a63

Please sign in to comment.