3 namespace Drupal\forum;
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Configure forum settings for this site.
13 class ForumSettingsForm extends ConfigFormBase {
18 public function getFormId() {
19 return 'forum_admin_settings';
25 protected function getEditableConfigNames() {
26 return ['forum.settings'];
32 public function buildForm(array $form, FormStateInterface $form_state) {
33 $config = $this->config('forum.settings');
35 $options = [5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500];
36 $form['forum_hot_topic'] = [
38 '#title' => $this->t('Hot topic threshold'),
39 '#default_value' => $config->get('topics.hot_threshold'),
40 '#options' => array_combine($options, $options),
41 '#description' => $this->t('The number of replies a topic must have to be considered "hot".'),
43 $options = [10, 25, 50, 75, 100];
44 $form['forum_per_page'] = [
46 '#title' => $this->t('Topics per page'),
47 '#default_value' => $config->get('topics.page_limit'),
48 '#options' => array_combine($options, $options),
49 '#description' => $this->t('Default number of forum topics displayed per page.'),
52 1 => $this->t('Date - newest first'),
53 2 => $this->t('Date - oldest first'),
54 3 => $this->t('Posts - most active first'),
55 4 => $this->t('Posts - least active first'),
57 $form['forum_order'] = [
59 '#title' => $this->t('Default order'),
60 '#default_value' => $config->get('topics.order'),
61 '#options' => $forder,
62 '#description' => $this->t('Default display order for topics.'),
65 return parent::buildForm($form, $form_state);
71 public function submitForm(array &$form, FormStateInterface $form_state) {
72 $this->config('forum.settings')
73 ->set('topics.hot_threshold', $form_state->getValue('forum_hot_topic'))
74 ->set('topics.page_limit', $form_state->getValue('forum_per_page'))
75 ->set('topics.order', $form_state->getValue('forum_order'))
78 parent::submitForm($form, $form_state);