You are here

class QuizAdminForm in Quiz 8.6

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

Hierarchy

Expanded class hierarchy of QuizAdminForm

1 string reference to 'QuizAdminForm'
quiz.routing.yml in ./quiz.routing.yml
quiz.routing.yml

File

src/Form/QuizAdminForm.php, line 12

Namespace

Drupal\quiz\Form
View source
class QuizAdminForm extends ConfigFormBase {
  protected function getEditableConfigNames() : array {
    return [
      'quiz.settings',
    ];
  }
  public function getFormId() : string {
    return 'quiz_admin_settings';
  }

  /**
   * This builds the main settings form for the quiz module.
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state
      ->cleanValues();
    $this
      ->config('quiz.settings')
      ->setData($form_state
      ->getValues())
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
QuizAdminForm::buildForm function This builds the main settings form for the quiz module. Overrides ConfigFormBase::buildForm
QuizAdminForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
QuizAdminForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
QuizAdminForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.