Commit 79d1d4c6 authored by webchick's avatar webchick

Issue #1925252 by larowlan: Convert forum's system_config_form() to SystemConfigFormBase.

parent a2ab6eac
......@@ -230,51 +230,6 @@ function forum_confirm_delete_submit($form, &$form_state) {
return;
}
/**
* Form constructor for the forum settings page.
*
* @see forum_menu()
* @see system_settings_form()
* @ingroup forms
*/
function forum_admin_settings($form, &$form_state) {
$config = config('forum.settings');
$number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500));
$form['forum_hot_topic'] = array('#type' => 'select',
'#title' => t('Hot topic threshold'),
'#default_value' => $config->get('topics.hot_threshold'),
'#options' => $number,
'#description' => t('The number of replies a topic must have to be considered "hot".'),
);
$number = drupal_map_assoc(array(10, 25, 50, 75, 100));
$form['forum_per_page'] = array('#type' => 'select',
'#title' => t('Topics per page'),
'#default_value' => $config->get('topics.page_limit'),
'#options' => $number,
'#description' => t('Default number of forum topics displayed per page.'),
);
$forder = array(1 => t('Date - newest first'), 2 => t('Date - oldest first'), 3 => t('Posts - most active first'), 4 => t('Posts - least active first'));
$form['forum_order'] = array('#type' => 'radios',
'#title' => t('Default order'),
'#default_value' => $config->get('topics.order'),
'#options' => $forder,
'#description' => t('Default display order for topics.'),
);
return system_config_form($form, $form_state);
}
/**
* Form submission handler for forum_admin_settings().
*/
function forum_admin_settings_submit($form, &$form_state) {
config('forum.settings')
->set('topics.hot_threshold', $form_state['values']['forum_hot_topic'])
->set('topics.page_limit', $form_state['values']['forum_per_page'])
->set('topics.order', $form_state['values']['forum_order'])
->save();
}
/**
* Form constructor for the forum overview form.
*
......
......@@ -138,13 +138,10 @@ function forum_menu() {
);
$items['admin/structure/forum/settings'] = array(
'title' => 'Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('forum_admin_settings'),
'access arguments' => array('administer forums'),
'weight' => 100,
'type' => MENU_LOCAL_TASK,
'parent' => 'admin/structure/forum',
'file' => 'forum.admin.inc',
'route_name' => 'forum_settings',
);
$items['admin/structure/forum/edit/container/%taxonomy_term'] = array(
'title' => 'Edit container',
......
forum_settings:
pattern: '/admin/structure/forum/settings'
defaults:
_form: '\Drupal\forum\ForumSettingsForm'
requirements:
_permission: 'administer forums'
<?php
/**
* @file
* Contains \Drupal\forum\ForumSettingsForm.
*/
namespace Drupal\forum;
use Drupal\system\SystemConfigFormBase;
/**
* Configure forum settings for this site.
*/
class ForumSettingsForm extends SystemConfigFormBase {
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'forum_admin_settings';
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('forum.settings');
$number = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500));
$form['forum_hot_topic'] = array(
'#type' => 'select',
'#title' => t('Hot topic threshold'),
'#default_value' => $config->get('topics.hot_threshold'),
'#options' => $number,
'#description' => t('The number of replies a topic must have to be considered "hot".'),
);
$number = drupal_map_assoc(array(10, 25, 50, 75, 100));
$form['forum_per_page'] = array(
'#type' => 'select',
'#title' => t('Topics per page'),
'#default_value' => $config->get('topics.page_limit'),
'#options' => $number,
'#description' => t('Default number of forum topics displayed per page.'),
);
$forder = array(
1 => t('Date - newest first'),
2 => t('Date - oldest first'),
3 => t('Posts - most active first'),
4 => t('Posts - least active first')
);
$form['forum_order'] = array(
'#type' => 'radios',
'#title' => t('Default order'),
'#default_value' => $config->get('topics.order'),
'#options' => $forder,
'#description' => t('Default display order for topics.'),
);
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('forum.settings')
->set('topics.hot_threshold', $form_state['values']['forum_hot_topic'])
->set('topics.page_limit', $form_state['values']['forum_per_page'])
->set('topics.order', $form_state['values']['forum_order'])
->save();
parent::submitForm($form, $form_state);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment