You are here

function QuizAdminForm::buildForm in Quiz 8.6

Same name and namespace in other branches
  1. 8.5 src/Form/QuizAdminForm.php \Drupal\quiz\Form\QuizAdminForm::buildForm()
  2. 6.x src/Form/QuizAdminForm.php \Drupal\quiz\Form\QuizAdminForm::buildForm()

This builds the main settings form for the quiz module.

Overrides ConfigFormBase::buildForm

File

src/Form/QuizAdminForm.php, line 25

Class

QuizAdminForm

Namespace

Drupal\quiz\Form

Code

function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('quiz.settings');
  $form['quiz_global_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global configuration'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t("Control aspects of the Quiz module's display"),
  );
  $form['quiz_global_settings']['revisioning'] = array(
    '#type' => 'checkbox',
    '#title' => t('Revisioning'),
    '#default_value' => $config
      ->get('revisioning'),
    '#description' => t('<strong>Warning: this will impact reporting.</strong><br/>Allow Quiz editors to create new revisions of Quizzes and Questions that have attempts.<br/>Leave this unchecked to prevent edits to Quizzes or Questions that have attempts (recommended).<br/>To make changes to a quiz in progress without revisioning, the user must have the "override quiz revisioning" permission.'),
  );
  $form['quiz_global_settings']['durod'] = array(
    '#type' => 'checkbox',
    '#title' => t('Delete results when a user is deleted'),
    '#default_value' => $config
      ->get('durod', 0),
    '#description' => t('When a user is deleted delete any and all results for that user.'),
  );
  $form['quiz_global_settings']['default_close'] = array(
    '#type' => 'number',
    '#title' => t('Default number of days before a @quiz is closed', array(
      '@quiz' => _quiz_get_quiz_name(),
    )),
    '#default_value' => $config
      ->get('default_close', 30),
    '#size' => 4,
    '#min' => 0,
    '#maxlength' => 4,
    '#description' => t('Supply a number of days to calculate the default close date for new quizzes.'),
  );
  $form['quiz_global_settings']['use_passfail'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow quiz creators to set a pass/fail option when creating a @quiz.', array(
      '@quiz' => strtolower(_quiz_get_quiz_name()),
    )),
    '#default_value' => $config
      ->get('use_passfail', 1),
    '#description' => t('Check this to display the pass/fail options in the @quiz form. If you want to prohibit other quiz creators from changing the default pass/fail percentage, uncheck this option.', array(
      '@quiz' => _quiz_get_quiz_name(),
    )),
  );
  $form['quiz_global_settings']['remove_partial_quiz_record'] = array(
    '#title' => t('Remove incomplete quiz records (older than)'),
    '#description' => t('Number of days to keep incomplete quiz attempts.'),
    '#default_value' => $config
      ->get('remove_partial_quiz_record', 0),
    '#type' => Drupal::moduleHandler()
      ->moduleExists('timeperiod') ? 'timeperiod_select' : 'textfield',
    '#units' => array(
      '86400' => array(
        'max' => 30,
        'step size' => 1,
      ),
      '3600' => array(
        'max' => 24,
        'step size' => 1,
      ),
      '60' => array(
        'max' => 60,
        'step size' => 1,
      ),
    ),
  );
  $form['quiz_global_settings']['remove_invalid_quiz_record'] = array(
    '#title' => t('Remove invalid quiz records (older than)'),
    '#description' => t('Number of days to keep invalid quiz attempts.'),
    '#default_value' => $config
      ->get('remove_invalid_quiz_record', 86400),
    '#type' => Drupal::moduleHandler()
      ->moduleExists('timeperiod') ? 'timeperiod_select' : 'textfield',
    '#units' => array(
      '86400' => array(
        'max' => 30,
        'step size' => 1,
      ),
      '3600' => array(
        'max' => 24,
        'step size' => 1,
      ),
      '60' => array(
        'max' => 60,
        'step size' => 1,
      ),
    ),
  );
  $form['quiz_global_settings']['autotitle_length'] = array(
    '#type' => 'number',
    '#title' => t('Length of automatically set question titles'),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t("Integer between 0 and 128. If the question creator doesn't set a question title the system will make a title automatically. Here you can decide how long the autotitle can be."),
    '#default_value' => $config
      ->get('autotitle_length', 50),
    '#min' => 0,
    '#max' => 128,
  );
  $form['quiz_global_settings']['pager_start'] = array(
    '#type' => 'number',
    '#title' => t('Pager start'),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('If a quiz has this many questions, a pager will be displayed instead of a select box.'),
    '#default_value' => $config
      ->get('pager_start', 100),
  );
  $form['quiz_global_settings']['pager_siblings'] = array(
    '#type' => 'number',
    '#title' => t('Pager siblings'),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('Number of siblings to show.'),
    '#default_value' => $config
      ->get('pager_siblings', 5),
  );
  $form['quiz_global_settings']['time_limit_buffer'] = array(
    '#type' => 'number',
    '#title' => t('Time limit buffer'),
    '#size' => 3,
    '#maxlength' => 3,
    '#description' => t('How many seconds after the time limit runs out to allow answers.'),
    '#default_value' => $config
      ->get('time_limit_buffer', 5),
  );

  // Review options.
  $review_options = quiz_get_feedback_options();
  $form['quiz_global_settings']['admin_review_options']['#title'] = t('Administrator review options');
  $form['quiz_global_settings']['admin_review_options']['#type'] = 'fieldset';
  $form['quiz_global_settings']['admin_review_options']['#description'] = t('Control what feedback types quiz administrators will see when viewing results for other users.');
  foreach (Drupal\quiz\Entity\QuizFeedbackType::loadMultiple() as $key => $when) {
    $form['quiz_global_settings']['admin_review_options']["admin_review_options_{$key}"] = array(
      '#title' => $when
        ->label(),
      '#title' => $when
        ->get('description'),
      '#type' => 'checkboxes',
      '#options' => $review_options,
      '#default_value' => $config
        ->get("admin_review_options_{$key}", array()),
    );
  }
  $target = array(
    'attributes' => array(
      'target' => '_blank',
    ),
  );
  $url = Url::fromUri('https://drupal.org/project/jquery_countdown', $target);
  $links = array(
    '@jquery_countdown' => Link::fromTextAndUrl(t('JQuery Countdown'), $url)
      ->toString(),
  );
  $form['quiz_addons'] = array(
    '#type' => 'fieldset',
    '#title' => t('Addons configuration'),
    '#description' => t('Quiz has built in integration with some other modules. Disabled checkboxes indicates that modules are not enabled.', $links),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['quiz_addons']['has_timer'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display timer'),
    '#default_value' => $config
      ->get('has_timer', 0),
    '#description' => t("@jquery_countdown is an <strong>optional</strong> module for Quiz. It is used to display a timer when taking a quiz. Without this timer, the user will not know how much time they have left to complete the Quiz.", $links),
    '#disabled' => !function_exists('jquery_countdown_add'),
  );
  $form['quiz_look_feel'] = array(
    '#type' => 'fieldset',
    '#title' => t('Look and feel'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t("Control aspects of the Quiz module's display"),
  );
  $form['quiz_look_feel']['_quiz_get_quiz_name()'] = array(
    '#type' => 'textfield',
    '#title' => t('Display name'),
    '#default_value' => _quiz_get_quiz_name(),
    '#description' => t('Change the name of the quiz type. Do you call it <em>test</em> or <em>assessment</em> instead? Change the display name of the module to something else. By default, it is called <em>Quiz</em>.'),
    '#required' => TRUE,
  );

  //$form['#validate'][] = 'quiz_settings_form_validate';

  //$form['#submit'][] = 'quiz_settings_form_submit';
  return parent::buildForm($form, $form_state);
}