class StatisticsSettingsForm

Configure statistics settings for this site.

Hierarchy

Expanded class hierarchy of StatisticsSettingsForm

1 string reference to 'StatisticsSettingsForm'
statistics.routing.yml in drupal/core/modules/statistics/statistics.routing.yml
drupal/core/modules/statistics/statistics.routing.yml

File

drupal/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php, line 17
Contains \Drupal\statistics\StatisticsSettingsForm.

Namespace

Drupal\statistics
View source
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;
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StatisticsSettingsForm::$moduleHandler protected property The module handler.
StatisticsSettingsForm::buildForm public function Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides SystemConfigFormBase::buildForm
StatisticsSettingsForm::create public static function Instantiates a new instance of this controller. Overrides SystemConfigFormBase::create
StatisticsSettingsForm::getFormID public function Implements \Drupal\Core\Form\FormInterface::getFormID(). Overrides FormInterface::getFormID
StatisticsSettingsForm::submitForm public function Implements \Drupal\Core\Form\FormInterface::submitForm(). Overrides SystemConfigFormBase::submitForm
StatisticsSettingsForm::__construct public function Constructs a \Drupal\user\StatisticsSettingsForm object. Overrides SystemConfigFormBase::__construct
SystemConfigFormBase::$configFactory protected property Stores the configuration factory.
SystemConfigFormBase::validateForm public function Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface::validateForm 7