Commit 3c7c0fca authored by Steven Ayers's avatar Steven Ayers
Browse files

git commit -m 'Issue #3300791 by bluegeek9: schema and config'...

git commit -m 'Issue #3300791 by bluegeek9: schema and config' --author="bluegeek9 <bluegeek9@1286304.no-reply.drupal.org>"
parent e0a9d661
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
chart_height: 430
chart_width: 700
exclude_administer_users: 0
flush_log_timer: 0
items_per_page: 10
show_last_registered_user: 1
show_published_nodes: 1
show_registered_users_count: 1
show_since_date: 1
show_total_visitors: 1
show_unique_visitor: 1
show_user_ip: 1
start_count_total_visitors: 0
theme: admin
+32 −0
Original line number Diff line number Diff line
visitors.config:
  type: config_object
  label: 'Visitors config'
  mapping:
    chart_height:
      type: integer
    chart_width:
      type: integer
    exclude_administer_users:
      type: boolean
    flush_log_timer:
      type: integer
    items_per_page:
      type: integer
    show_last_registered_user:
      type: boolean
    show_published_nodes:
      type: boolean
    show_registered_users_count:
      type: boolean
    show_since_date:
      type: boolean
    show_total_visitors:
      type: boolean
    show_unique_visitor:
      type: boolean
    show_user_ip:
      type: boolean
    start_count_total_visitors:
      type: integer
    theme:
      type: string
 No newline at end of file
+36 −70
Original line number Diff line number Diff line
@@ -14,6 +14,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 */
class Settings extends ConfigFormBase {

  /**
   * Config settings.
   *
   * @var string
   */
  const SETTINGS = 'visitors.config';


  /**
   * An extension discovery instance.
   *
@@ -51,13 +59,22 @@ class Settings extends ConfigFormBase {
    return 'visitors_admin_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      static::SETTINGS,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('visitors.config');
    $system_config = $this->config('system.theme');
    $form = [];
    $form = parent::buildForm($form, $form_state);

    $form['settings'] = [
      '#type' => 'fieldset',
@@ -234,85 +251,34 @@ class Settings extends ConfigFormBase {
      '#description' => $this->t('Chart height.'),
    ];

    return parent::buildForm($form, $form_state);;
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = \Drupal::configFactory()->getEditable('visitors.config');
    $config = $this->configFactory->getEditable(static::SETTINGS);
    $values = $form_state->getValues();

    $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(
        'theme',
        $form_state->getValue('theme')
      )
      ->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')
      )
      ->set('show_total_visitors', $values['show_total_visitors'])
      ->set('start_count_total_visitors', $values['start_count_total_visitors'])
      ->set('show_unique_visitor', $values['show_unique_visitor'])
      ->set('show_registered_users_count', $values['show_registered_users_count'])
      ->set('show_last_registered_user', $values['show_last_registered_user'])
      ->set('show_published_nodes', $values['show_published_nodes'])
      ->set('show_user_ip', $values['show_user_ip'])
      ->set('show_since_date', $values['show_since_date'])
      ->set('exclude_administer_users', $values['exclude_administer_users'])
      ->set('theme', $values['theme'])
      ->set('items_per_page', $values['items_per_page'])
      ->set('flush_log_timer', $values['flush_log_timer'])
      ->set('chart_width', $values['chart_width'])
      ->set('chart_height', $values['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 [];
  }

}
+0 −31
Original line number Diff line number Diff line
@@ -5,37 +5,6 @@
 * Install/uninstall visitors module.
 */

/**
 * Implements hook_install().
 */
function visitors_install() {
  \Drupal::configFactory()->getEditable('visitors.config')
    ->set('chart_height', 430)
    ->set('chart_width', 700)
    ->set('exclude_administer_users', 0)
    ->set('flush_log_timer', 0)
    ->set('items_per_page', 10)
    ->set('show_last_registered_user', 1)
    ->set('show_published_nodes', 1)
    ->set('show_registered_users_count', 1)
    ->set('show_since_date', 1)
    ->set('show_total_visitors', 1)
    ->set('show_unique_visitor', 1)
    ->set('show_user_ip', 1)
    ->set('start_count_total_visitors', 0)
    ->set('theme', 'admin')
    ->save();
}

/**
 * Implements hook_uninstall().
 */
function visitors_uninstall() {
  drupal_uninstall_schema('visitors');

  \Drupal::configFactory()->getEditable('visitors.config')->delete();
}

/**
 * Implements hook_schema().
 */