Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / forum / src / ForumSettingsForm.php
1 <?php
2
3 namespace Drupal\forum;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Configure forum settings for this site.
10  *
11  * @internal
12  */
13 class ForumSettingsForm extends ConfigFormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'forum_admin_settings';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function getEditableConfigNames() {
26     return ['forum.settings'];
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function buildForm(array $form, FormStateInterface $form_state) {
33     $config = $this->config('forum.settings');
34
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'] = [
37       '#type' => 'select',
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".'),
42     ];
43     $options = [10, 25, 50, 75, 100];
44     $form['forum_per_page'] = [
45       '#type' => 'select',
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.'),
50     ];
51     $forder = [
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'),
56     ];
57     $form['forum_order'] = [
58       '#type' => 'radios',
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.'),
63     ];
64
65     return parent::buildForm($form, $form_state);
66   }
67
68   /**
69    * {@inheritdoc}
70    */
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'))
76       ->save();
77
78     parent::submitForm($form, $form_state);
79   }
80
81 }