You are here

class Settings in Visitors 8.2

Hierarchy

Expanded class hierarchy of Settings

1 string reference to 'Settings'
visitors.routing.yml in ./visitors.routing.yml
visitors.routing.yml

File

src/Form/Settings.php, line 12

Namespace

Drupal\visitors\Form
View source
class Settings extends ConfigFormBase {
  public function getFormID() {
    return 'visitors_admin_settings';
  }
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = \Drupal::config('visitors.config');
    $form = array();
    $form['settings'] = array(
      '#type' => 'fieldset',
      '#weight' => -30,
      '#title' => t('Visitors block'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#description' => t('Visitors block settings'),
    );
    $form['settings']['show_total_visitors'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show Total Visitors'),
      '#default_value' => $config
        ->get('show_total_visitors'),
      '#description' => t('Show Total Visitors.'),
    );
    $form['settings']['start_count_total_visitors'] = array(
      '#type' => 'textfield',
      '#title' => t('Total visitors start count'),
      '#default_value' => $config
        ->get('start_count_total_visitors'),
      '#description' => t('Start the count of the total visitors at this number. Useful for including the known number of visitors in the past.'),
    );
    $form['settings']['show_unique_visitor'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show Unique Visitors'),
      '#default_value' => $config
        ->get('show_unique_visitor'),
      '#description' => t('Show Unique Visitors based on their IP.'),
    );
    $form['settings']['show_registered_users_count'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show Registered Users Count'),
      '#default_value' => $config
        ->get('show_registered_users_count'),
      '#description' => t('Show Registered Users.'),
    );
    $form['settings']['show_last_registered_user'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show Last Registered User'),
      '#default_value' => $config
        ->get('show_last_registered_user'),
      '#description' => t('Show Last Registered User.'),
    );
    $form['settings']['show_published_nodes'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show Published Nodes'),
      '#default_value' => $config
        ->get('show_published_nodes'),
      '#description' => t('Show Published Nodes.'),
    );
    $form['settings']['show_user_ip'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show User IP'),
      '#default_value' => $config
        ->get('show_user_ip'),
      '#description' => t('Show User IP.'),
    );
    $form['settings']['show_since_date'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show Since Date'),
      '#default_value' => $config
        ->get('show_since_date'),
      '#description' => t('Show Since Date.'),
    );

    // Statistics settings.
    $form['statistics'] = array(
      '#type' => 'fieldset',
      '#title' => t('Visitors statistics'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#description' => t('Visitors statistics settings'),
    );
    $form['statistics']['exclude_administer_users'] = array(
      '#type' => 'checkbox',
      '#title' => t('Exclude administer users from statistics'),
      '#default_value' => $config
        ->get('exclude_administer_users'),
      '#description' => t('Exclude hits of administer users from statistics.'),
    );
    $form['statistics']['items_per_page'] = array(
      '#type' => 'select',
      '#title' => 'Items per page',
      '#default_value' => $config
        ->get('items_per_page'),
      '#options' => array(
        5 => 5,
        10 => 10,
        25 => 25,
        50 => 50,
        100 => 100,
        200 => 200,
        250 => 250,
        500 => 500,
        1000 => 1000,
      ),
      '#description' => t('The default maximum number of items to display per page.'),
    );
    $form['statistics']['flush_log_timer'] = array(
      '#type' => 'select',
      '#title' => t('Discard visitors logs older than'),
      '#default_value' => $config
        ->get('flush_log_timer'),
      '#options' => array(
        0 => 'Never',
        3600 => '1 hour',
        10800 => '3 hours',
        21600 => '6 hours',
        32400 => '9 hours',
        43200 => '12 hours',
        86400 => '1 day',
        172800 => '2 days',
        259200 => '3 days',
        604800 => '1 week',
        1209600 => '2 weeks',
        2419200 => '4 weeks',
        4838400 => '1 month 3 weeks',
        9676800 => '3 months 3 weeks',
        31536000 => '1 year',
      ),
      '#description' => $this
        ->t('Older visitors log entries (including referrer statistics) will be ' . 'automatically discarded. (Requires a correctly configured ' . '<a href="@cron">cron maintenance task</a>.)', array(
        '@cron' => Url::fromRoute('system.status')
          ->toString(),
      )),
    );

    // Chart settings.
    $form['chart_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Chart settings'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#description' => t('Visitors chart settings'),
    );
    $form['chart_settings']['chart_width'] = array(
      '#type' => 'textfield',
      '#title' => t('Width'),
      '#default_value' => $config
        ->get('chart_width'),
      '#description' => t('Chart width.'),
    );
    $form['chart_settings']['chart_height'] = array(
      '#type' => 'textfield',
      '#title' => t('Height'),
      '#default_value' => $config
        ->get('chart_height'),
      '#description' => t('Chart height.'),
    );
    return parent::buildForm($form, $form_state);
  }
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = \Drupal::configFactory()
      ->getEditable('visitors.config');
    $config
      ->set('show_total_visitors', (int) $form_state
      ->getValue('show_total_visitors'))
      ->set('start_count_total_visitors', (int) $form_state
      ->getValue('start_count_total_visitors'))
      ->set('show_unique_visitor', (int) $form_state
      ->getValue('show_unique_visitor'))
      ->set('show_registered_users_count', (int) $form_state
      ->getValue('show_registered_users_count'))
      ->set('show_last_registered_user', (int) $form_state
      ->getValue('show_last_registered_user'))
      ->set('show_published_nodes', (int) $form_state
      ->getValue('show_published_nodes'))
      ->set('show_user_ip', (int) $form_state
      ->getValue('show_user_ip'))
      ->set('show_since_date', (int) $form_state
      ->getValue('show_since_date'))
      ->set('exclude_administer_users', (int) $form_state
      ->getValue('exclude_administer_users'))
      ->set('items_per_page', (int) $form_state
      ->getValue('items_per_page'))
      ->set('flush_log_timer', (int) $form_state
      ->getValue('flush_log_timer'))
      ->set('chart_width', (int) $form_state
      ->getValue('chart_width'))
      ->set('chart_height', (int) $form_state
      ->getValue('chart_height'))
      ->save();
    parent::submitForm($form, $form_state);
  }

  /**
   * Gets the configuration names that will be editable.
   *
   * @return array
   *   An array of configuration object names that are editable if called in
   *   conjunction with the trait's config() method.
   */
  protected function getEditableConfigNames() {
    return array();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
FormInterface::getFormId public function Returns a unique string identifying the form. 236
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
Settings::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
Settings::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
Settings::getFormID public function
Settings::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.