diff --git a/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php b/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php new file mode 100644 index 0000000000000000000000000000000000000000..e5eddbc29adbdf3b1981c167f7bdd3c7bae9645d --- /dev/null +++ b/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php @@ -0,0 +1,94 @@ +configFactory = $config_factory; + $this->moduleHandler = $module_handler; + } + + /** + * Implements \Drupal\Core\ControllerInterface::create(). + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('module_handler') + ); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::getFormID(). + */ + public function getFormID() { + return 'statistics_settings_form'; + } + + /** + * Implements \Drupal\Core\Form\FormInterface::buildForm(). + */ + public function buildForm(array $form, array &$form_state) { + $config = $this->configFactory->get('statistics.settings'); + + // Content counter settings. + $form['content'] = array( + '#type' => 'details', + '#title' => t('Content viewing counter settings'), + ); + $form['content']['statistics_count_content_views'] = array( + '#type' => 'checkbox', + '#title' => t('Count content views'), + '#default_value' => $config->get('count_content_views'), + '#description' => t('Increment a counter each time content is viewed.'), + ); + + return parent::buildForm($form, $form_state); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + public function submitForm(array &$form, array &$form_state) { + $this->configFactory->get('statistics.settings') + ->set('count_content_views', $form_state['values']['statistics_count_content_views']) + ->save(); + + // The popular statistics block is dependent on these settings, so clear the + // block plugin definitions cache. + if ($this->moduleHandler->moduleExists('block')) { + drupal_container()->get('plugin.manager.block')->clearCachedDefinitions(); + } + + parent::submitForm($form, $form_state); + } + +} diff --git a/core/modules/statistics/statistics.admin.inc b/core/modules/statistics/statistics.admin.inc deleted file mode 100644 index d454321c07923d918d102a1596306d7621bfd9f2..0000000000000000000000000000000000000000 --- a/core/modules/statistics/statistics.admin.inc +++ /dev/null @@ -1,46 +0,0 @@ - 'details', - '#title' => t('Content viewing counter settings'), - ); - $form['content']['statistics_count_content_views'] = array( - '#type' => 'checkbox', - '#title' => t('Count content views'), - '#default_value' => $config->get('count_content_views'), - '#description' => t('Increment a counter each time content is viewed.'), - ); - - return system_config_form($form, $form_state); -} - -/** - * Form submission handler for statistics_settings_form(). - */ -function statistics_settings_form_submit($form, &$form_state) { - config('statistics.settings') - ->set('count_content_views', $form_state['values']['statistics_count_content_views']) - ->save(); - // The popular statistics block is dependent on these settings, so clear the - // block plugin definitions cache. - if (module_exists('block')) { - drupal_container()->get('plugin.manager.block')->clearCachedDefinitions(); - } -} diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index f6a9d48bf352545cbc5b9c2fdeb0b966b8036f90..6510818ebf57d82bec2b7a47ee30b5294a95a78c 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -79,10 +79,8 @@ function statistics_menu() { $items['admin/config/system/statistics'] = array( 'title' => 'Statistics', 'description' => 'Control details about what and how your site logs content statistics.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('statistics_settings_form'), + 'route_name' => 'statistics_settings', 'access arguments' => array('administer statistics'), - 'file' => 'statistics.admin.inc', 'weight' => -15, ); return $items; diff --git a/core/modules/statistics/statistics.routing.yml b/core/modules/statistics/statistics.routing.yml new file mode 100644 index 0000000000000000000000000000000000000000..0d0310f0a7b6352c45a37bece4c283f89e8e543a --- /dev/null +++ b/core/modules/statistics/statistics.routing.yml @@ -0,0 +1,6 @@ +statistics_settings: + pattern: '/admin/config/system/statistics' + defaults: + _form: 'Drupal\statistics\StatisticsSettingsForm' + requirements: + _permission: 'administer statistics'