summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-03-10 06:36:17 (GMT)
committerwebchick2013-03-10 06:36:17 (GMT)
commit96903932a19c2d60a545dd72af53b33d09ecaefc (patch)
tree6b9913ff63db0723692c34609404ad6280141cde
parent232cfc74914b8776493b74d4f33566c1cfecd23c (diff)
Issue #1937968 by ACF: Convert statistics's system_config_form() to SystemConfigFormBase.
-rw-r--r--core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php94
-rw-r--r--core/modules/statistics/statistics.admin.inc46
-rw-r--r--core/modules/statistics/statistics.module4
-rw-r--r--core/modules/statistics/statistics.routing.yml6
4 files changed, 101 insertions, 49 deletions
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 0000000..e5eddbc
--- /dev/null
+++ b/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php
@@ -0,0 +1,94 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\statistics\StatisticsSettingsForm.
+ */
+
+namespace Drupal\statistics;
+
+use Drupal\system\SystemConfigFormBase;
+use Drupal\Core\Config\ConfigFactory;
+use Drupal\Core\Extension\ModuleHandler;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Configure statistics settings for this site.
+ */
+class StatisticsSettingsForm extends SystemConfigFormBase {
+
+ /**
+ * The module handler.
+ *
+ * @var \Drupal\Core\Extension\ModuleHandler
+ */
+ protected $moduleHandler;
+
+ /**
+ * Constructs a \Drupal\user\StatisticsSettingsForm object.
+ *
+ * @param \Drupal\Core\Config\ConfigFactory $config_factory
+ * The factory for configuration objects.
+ * @param \Drupal\Core\Extension\ModuleHandler $module_handler
+ * The module handler.
+ */
+ public function __construct(ConfigFactory $config_factory, ModuleHandler $module_handler) {
+ $this->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 d454321c..0000000
--- a/core/modules/statistics/statistics.admin.inc
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-
-/**
- * @file
- * Admin page callbacks for the Statistics module.
- */
-
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-
-/**
- * Form constructor for the statistics administration form.
- *
- * @ingroup forms
- * @see statistics_settings_form_submit().
- */
-function statistics_settings_form($form, &$form_state) {
- $config = config('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 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 f6a9d48..6510818 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 0000000..0d0310f
--- /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'