class SettingsForm in Private files download permission 3.x
Same name and namespace in other branches
- 8.2 src/Form/SettingsForm.php \Drupal\pfdp\Form\SettingsForm
Settings form for private_files_download_permission.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\pfdp\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 11
Namespace
Drupal\pfdp\FormView source
class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'pfdp_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'pfdp.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$settings = \Drupal::config('pfdp.settings');
// Prepare the fields.
$form['by_user_checks'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable by-user checks'),
'#default_value' => $settings
->get('by_user_checks'),
'#description' => $this
->t('You may wish to disable this feature if there are plenty of users, as it may slow down the entire site.'),
];
$form['cache_users'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Cache user list'),
'#default_value' => $settings
->get('cache_users'),
'#description' => $this
->t('For sites with lots of users, this will save on load time when editing directory settings.'),
'#states' => [
'visible' => [
':input[name="by_user_checks"]' => [
'checked' => TRUE,
],
],
'enabled' => [
':input[name="by_user_checks"]' => [
'checked' => TRUE,
],
],
],
];
$form['attachment_mode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable attachment mode'),
'#default_value' => $settings
->get('attachment_mode'),
'#description' => $this
->t('Have files downloaded as attachments instead of displayed inline in the browser.'),
];
$form['override_mode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable override mode'),
'#default_value' => $settings
->get('override_mode'),
'#description' => $this
->t('Skip the system-wide validation chain and download files immediately.'),
];
$form['debug_mode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable debug mode'),
'#default_value' => $settings
->get('debug_mode'),
'#description' => $this
->t('Turn on logging to debug issues.'),
];
// Prepare the submit button.
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save settings'),
];
// Return the form.
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$settings = \Drupal::configFactory()
->getEditable('pfdp.settings');
// Save all settings.
$settings
->set('by_user_checks', $form_state
->getValue('by_user_checks'))
->save();
if (!$form_state
->getValue('by_user_checks')) {
$settings
->set('cache_users', FALSE)
->save();
}
else {
$settings
->set('cache_users', $form_state
->getValue('cache_users'))
->save();
}
$settings
->set('attachment_mode', $form_state
->getValue('attachment_mode'))
->save();
$settings
->set('override_mode', $form_state
->getValue('override_mode'))
->save();
$settings
->set('debug_mode', $form_state
->getValue('debug_mode'))
->save();
// Display the status message.
\Drupal::messenger()
->addStatus($this
->t('Your settings were saved successfully.'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
18 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 16 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
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. | |
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. | |
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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |