class TrackDaFilesSettingsForm in Track da files 8
Configure book settings for this site.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\track_da_files\Form\TrackDaFilesSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of TrackDaFilesSettingsForm
1 string reference to 'TrackDaFilesSettingsForm'
File
- src/
Form/ TrackDaFilesSettingsForm.php, line 11
Namespace
Drupal\track_da_files\FormView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TrackDaFilesSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
TrackDaFilesSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
TrackDaFilesSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
TrackDaFilesSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |