class SettingsForm in Improved Multi Select 8
Class SettingsForm.
Defines improved_multi_select settings form.
@package Drupal\improved_multi_select\Form
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\improved_multi_select\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 15
Namespace
Drupal\improved_multi_select\FormView source
class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ims_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'improved_multi_select.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('improved_multi_select.settings');
$form['isall'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Replace all multi-select lists'),
'#default_value' => $config
->get('isall'),
];
$form['url'] = [
'#type' => 'textarea',
'#title' => $this
->t('Replace multi-select lists on specific pages'),
'#description' => $this
->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", [
'%blog' => '/blog',
'%blog-wildcard' => '/blog/*',
'%front' => '<front>',
]),
'#default_value' => $config
->get('url'),
];
$form['selectors'] = [
'#type' => 'textarea',
'#title' => $this
->t('Replace multi-select with specified selectors'),
'#description' => $this
->t('Enter jQuery selectors (one selector per line). Example: select[multiple]'),
'#default_value' => $config
->get('selectors'),
];
$form['placeholder_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Search box placeholder text'),
'#description' => $this
->t('Enter placeholder text to appear in search box'),
'#default_value' => $config
->get('placeholder_text'),
];
$form['filtertype'] = [
'#type' => 'radios',
'#title' => $this
->t('Filter functionality'),
'#description' => $this
->t('Choose how you would like the filter textfield to function.'),
'#options' => [
'partial' => $this
->t('Partial match: Shows options that contain the filter text.'),
'exact' => $this
->t('Exact match: Shows options that exactly match the filter text.'),
'anywords' => $this
->t('Any words: Shows options that contain any of the individual words in the filter text. Only exact word matches count.'),
'anywords_partial' => $this
->t('Any words (partial): Shows options that contain any of the individual words in the filter text. Partial word matches count.'),
'allwords' => $this
->t('All words: Shows options that contain all of the individual words in the filter text (in any order). Only exact word matches count.'),
'allwords_partial' => $this
->t('All words (partial): Shows options that contain all of the individual words in the filter text (in any order). Partial word matches count.'),
],
'#default_value' => $config
->get('filtertype'),
];
$form['js_regex'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow JavaScript regular expressions in filter'),
'#description' => $this
->t('If checked, a site visitor will be able to use JavaScript regular expressions in the filter input.'),
'#default_value' => $config
->get('js_regex'),
];
$form['orderable'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Allow re-ordering of selected items'),
'#description' => $this
->t('If checked, the user will be able to re-order the selected items using "Move up" and "Move down" buttons. Also, when adding items they will remain in the order they were added instead of keeping the order of the original field. Note: some Drupal fields (like list) will keep this order on an entity view, but will not keep this order on an entity edit form. You have to use the <em>IMS options widget</em> submodule or alter your edit form.'),
'#default_value' => $config
->get('orderable'),
];
$form['groupresetfilter'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Reset filter when selecting a group'),
'#description' => $this
->t('If checked and a select has optgroups, when a group is selected the filter text field is cleared. If unchecked, any existing filter will be applied only to items of the selected group.'),
'#default_value' => $config
->get('groupresetfilter'),
];
$form['remove_required_attr'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Remove required attribute'),
'#description' => $this
->t('If checked removes the required attribute from select elements to allow form submission and validation on Drupal side. Otherwise mandatory HTML5 popup not showed because html select element is hidden by JavaScript.'),
'#default_value' => $config
->get('remove_required_attr'),
];
$form['button_text'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Button text'),
'#description' => $this
->t('Set the text used for the improved multi-select buttons.'),
];
$form['button_text']['buttontext_add'] = [
'#type' => 'textfield',
'#title' => $this
->t('Add button'),
'#default_value' => $config
->get('buttontext_add'),
];
$form['button_text']['buttontext_addall'] = [
'#type' => 'textfield',
'#title' => $this
->t('Add all button'),
'#default_value' => $config
->get('buttontext_addall'),
];
$form['button_text']['buttontext_del'] = [
'#type' => 'textfield',
'#title' => $this
->t('Remove button'),
'#default_value' => $config
->get('buttontext_del'),
];
$form['button_text']['buttontext_delall'] = [
'#type' => 'textfield',
'#title' => $this
->t('Remove all button'),
'#default_value' => $config
->get('buttontext_delall'),
];
$form['button_text']['buttontext_moveup'] = [
'#type' => 'textfield',
'#title' => $this
->t('Move up button'),
'#default_value' => $config
->get('buttontext_moveup'),
// Hide the settings when the move buttons are disabled.
'#states' => [
'invisible' => [
':input[name="orderable"]' => [
'checked' => FALSE,
],
],
],
];
$form['button_text']['buttontext_movedown'] = [
'#type' => 'textfield',
'#title' => $this
->t('Move down button'),
'#default_value' => $config
->get('buttontext_movedown'),
'#states' => [
// Hide the settings when the move buttons are disabled.
'invisible' => [
':input[name="orderable"]' => [
'checked' => FALSE,
],
],
],
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values_to_save = [
'isall',
'url',
'selectors',
'placeholder_text',
'filtertype',
'orderable',
'js_regex',
'groupresetfilter',
'remove_required_attr',
'buttontext_add',
'buttontext_addall',
'buttontext_del',
'buttontext_delall',
'buttontext_moveup',
'buttontext_movedown',
];
$values = $form_state
->getValues();
foreach ($values as $key => $value) {
if (array_search($key, $values_to_save) === FALSE) {
unset($values[$key]);
}
}
$this
->config('improved_multi_select.settings')
->setData($values)
->save();
}
}
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. | |
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:: |
|
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. | |
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. |