You are here

class TrackDaFilesSettingsForm in Track da files 8

Configure book settings for this site.

Hierarchy

Expanded class hierarchy of TrackDaFilesSettingsForm

1 string reference to 'TrackDaFilesSettingsForm'
track_da_files.routing.yml in ./track_da_files.routing.yml
track_da_files.routing.yml

File

src/Form/TrackDaFilesSettingsForm.php, line 11

Namespace

Drupal\track_da_files\Form
View source
class TrackDaFilesSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'track_da_files_admin_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'track_da_files.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->configFactory
      ->get('track_da_files.settings');

    // Variable which stores options to show in main reports.
    $displays_datas = $config
      ->get('displays_datas');

    // Variable which stores datas that will appear in files displays reports.
    $files_datas = $config
      ->get('files_datas');

    // Variable which stores stores options to show in file specific report.
    $single_file_datas = $config
      ->get('single_file_datas');

    // Variable which stores value for enabling user specific report.
    $user_report_enabled = $config
      ->get('user_report_enabled');

    // Variable which stores stores options to show in user specific report.
    $single_user_datas = $config
      ->get('single_user_datas');

    // Variable storing value for enabling showing tracking datas on the site.
    $file_field_links_show_enabled = $config
      ->get('file_field_links_show_enabled');

    //if (module_exists('colorbox')) {
    if (\Drupal::moduleHandler()
      ->moduleExists('colorbox')) {
      $colorbox_enabled = $config
        ->get('colorbox_enabled');
    }
    $form['track_da_files'] = array(
      /* Some bug with vertical tabs, so temporary I put nested fieldsets */
      '#type' => 'details',
      /* '#type' => 'vertical_tabs', */
      '#title' => 'Reports availables datas',
    );

    // Main report configuration section.
    $form['track_da_files']['main_report'] = array(
      '#type' => 'details',
      '#title' => $this
        ->t('Main report'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['track_da_files']['main_report']['displays_datas'] = array(
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Displays datas to show in main report'),
      '#options' => array(
        'total_ips' => $this
          ->t('Total ips'),
        'average_by_ip' => $this
          ->t('Average count by ip'),
        'last_display' => $this
          ->t('Last display date'),
      ),
      '#default_value' => $displays_datas,
      '#description' => $this
        ->t('Datas that will appear in main files displays reports.'),
    );
    $form['track_da_files']['main_report']['files_datas'] = array(
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Files datas to show in main report'),
      '#options' => array(
        'created' => $this
          ->t('Created'),
        'filesize' => $this
          ->t('File size'),
        'filemime' => $this
          ->t('File mime'),
      ),
      '#default_value' => $files_datas,
      '#description' => $this
        ->t('Specific files datas that will appear in main report.'),
    );

    // File specific report configuration section.
    $form['track_da_files']['file_report'] = array(
      '#type' => 'details',
      '#title' => $this
        ->t('File report'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['track_da_files']['file_report']['single_file_datas'] = array(
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Displays datas to show in file report'),
      '#options' => array(
        'id' => $this
          ->t('Related content'),
        'browser' => $this
          ->t('Browser'),
        'browser_version' => $this
          ->t('Browser version'),
        'browser_platform' => $this
          ->t('Browser platform'),
        'referer' => $this
          ->t('Displayed from URL'),
        'ip' => $this
          ->t('Ip'),
        'uid' => $this
          ->t('User who displayed file'),
      ),
      '#default_value' => $single_file_datas,
      '#description' => $this
        ->t('Datas that will appear in file specific report.'),
    );

    // User specific report configuration section.
    $form['track_da_files']['user_report'] = array(
      '#type' => 'details',
      '#title' => $this
        ->t('User report'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['track_da_files']['user_report']['user_report_enabled'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable user specific report'),
      '#default_value' => $user_report_enabled,
    );
    $form['track_da_files']['user_report']['single_user_datas'] = array(
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Displays datas to show in user report'),
      '#options' => array(
        'browser' => $this
          ->t('Browser'),
        'browser_version' => $this
          ->t('Browser version'),
        'browser_platform' => $this
          ->t('Browser platform'),
        'referer' => $this
          ->t('Displayed from URL'),
        'ip' => $this
          ->t('Ip'),
      ),
      '#default_value' => $single_user_datas,
      '#description' => $this
        ->t('Datas that will appear in users displays reports.'),
      '#states' => array(
        'visible' => array(
          ':input[name=user_report_enabled]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );

    // Configure to show datas near from file field links.
    $form['track_da_files_file_field_links_show'] = array(
      '#type' => 'fieldset',
      '#title' => $this
        ->t('File field links'),
    );
    $form['track_da_files_file_field_links_show']['file_field_links_show_enabled'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Provide counter near file field links'),
      '#default_value' => $config
        ->get('file_field_links_show_enabled'),
      '#description' => $this
        ->t('A counter showing number of times a file has been displayed will appear in a near from files links'),
    );
    if (\Drupal::moduleHandler()
      ->moduleExists('colorbox')) {
      $form['track_da_files_colorbox'] = array(
        '#type' => 'fieldset',
        '#title' => $this
          ->t('Colorbox'),
      );
      $form['track_da_files_colorbox']['track_da_files_colorbox_enabled'] = array(
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Enable Track da files colorbox compatibility'),
        '#default_value' => $track_da_files_colorbox_enabled,
        '#description' => $this
          ->t('When enabled, in content interface select display "tdf : Colorbox image" for desired fields'),
      );
    }

    // Render the role overview.
    $form['track_da_files_roles']['role_settings'] = array(
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Roles'),
    );
    $form['track_da_files_roles']['role_settings']['roles'] = array(
      '#type' => 'radios',
      '#title' => $this
        ->t('Add tracking for roles'),
      '#options' => array(
        $this
          ->t('Add to the selected roles only'),
        $this
          ->t('Add to every role except the selected ones'),
      ),
      '#default_value' => $config
        ->get('roles'),
    );
    $role_options_array = user_roles();
    foreach ($role_options_array as $key => $value) {
      $role_options[] = $key;
    }
    $form['track_da_files_roles']['role_settings']['specific_roles'] = array(
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Roles'),
      '#default_value' => $config
        ->get('specific_roles'),
      '#options' => $role_options,
      '#description' => $this
        ->t('If none of the roles are selected, all users will be tracked. If a user has any of the roles checked, that user will be tracked (or excluded, depending on the setting above).'),
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */

  /* public function validateForm(array &$form, array &$form_state) {

      parent::validateForm($form, $form_state);
    }*/

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    $config = $this
      ->config('track_da_files.settings');
    $config
      ->set('displays_datas', $values['displays_datas'])
      ->save();
    $config
      ->set('files_datas', $values['files_datas'])
      ->save();
    $config
      ->set('single_file_datas', $values['single_file_datas'])
      ->save();
    $config
      ->set('user_report_enabled', $values['user_report_enabled'])
      ->save();
    $config
      ->set('single_user_datas', $values['single_user_datas'])
      ->save();
    $config
      ->set('file_field_links_show_enabled', $values['file_field_links_show_enabled'])
      ->save();
    $config
      ->set('roles', $values['roles'])
      ->save();
    $config
      ->set('specific_roles', $values['specific_roles'])
      ->save();
    parent::submitForm($form, $form_state);
  }

}

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
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.
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.
TrackDaFilesSettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
TrackDaFilesSettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
TrackDaFilesSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
TrackDaFilesSettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
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.