class ConfigurationForm in Views Natural Sort 8.2
Defines a form that configures Views Natural Sort's settings.
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\views_natural_sort\Form\ConfigurationForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of ConfigurationForm
1 string reference to 'ConfigurationForm'
File
- src/
Form/ ConfigurationForm.php, line 14
Namespace
Drupal\views_natural_sort\FormView source
class ConfigurationForm extends ConfigFormBase {
protected $viewsNaturalSort;
public function __construct(ViewsNaturalSortService $viewsNaturalSort) {
$this->viewsNaturalSort = $viewsNaturalSort;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('views_natural_sort.service'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'view_natural_sort_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'views_natural_sort.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config = $this
->config('views_natural_sort.settings');
// TODO: Change this to be handled by the transformation plugins.
$form['beginning_words_remove'] = [
'#type' => 'textfield',
'#title' => 'Words to filter from the beginning of a phrase',
'#default_value' => implode(',', $config
->get('transformation_settings.remove_beginning_words.settings')),
'#description' => $this
->t('Commonly, the words "A", "The", and "An" are removed when sorting book titles if they appear at the beginning of the title. Those would be great candidates for this field. Separate words with a comma.'),
];
$form['words_remove'] = [
'#type' => 'textfield',
'#title' => 'Words to filter from anywhere in a phrase',
'#default_value' => implode(',', $config
->get('transformation_settings.remove_words.settings')),
'#description' => $this
->t('Commonly used words like "of", "and", and "or" are removed when sorting book titles. Words you would like filtered go here. Separate words with a comma.'),
];
$form['symbols_remove'] = [
'#type' => 'textfield',
'#title' => 'Symbols to filter from anywhere in a phrase',
'#default_value' => $config
->get('transformation_settings.remove_symbols.settings'),
'#description' => $this
->t('Most symbols are ignored when performing a sort naturally. Those symbols you want ignored go here. Do not use a separator. EX: &$".'),
];
$form['days_of_the_week_enabled'] = [
'#type' => 'checkbox',
'#title' => 'Sort days of the week and their abbreviations',
'#description' => "Checking this setting will allow sorting of days of the week in their proper order starting with the day of the week that is configurable by you and for each language.",
'#efault_value' => $config
->get('transformation_settings.days_of_the_week.enabled'),
];
$form['rebuild_items_per_batch'] = [
'#type' => 'number',
'#title' => 'Items per Batch',
'#default_value' => $config
->get('rebuild_items_per_batch'),
'#min' => 0,
'#description' => $this
->t('The number of items a batch process will work through at a given time. Raising this number will make the batch go quicker, however, raising it too high can cause timeouts and/or memory limit errors.'),
];
$form['rebuild'] = [
'#type' => 'details',
'#title' => $this
->t('Incase of Emergency'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'button' => [
'#type' => 'submit',
'#description' => 'Incase of an emergency.',
'#value' => $this
->t('Rebuild Index'),
'#submit' => [
[
$this,
'submitFormReindexOnly',
],
],
],
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
// TODO: Change this to be handled by the transformation plugins.
$beginning_words_remove = explode(',', $values['beginning_words_remove']);
array_walk($beginning_words_remove, function (&$val) {
$val = trim($val);
});
$words_remove = explode(',', $values['words_remove']);
array_walk($words_remove, function (&$val) {
$val = trim($val);
});
$symbols_remove = trim($values['symbols_remove']);
$this
->config('views_natural_sort.settings')
->set('transformation_settings.remove_beginning_words.settings', $beginning_words_remove)
->set('transformation_settings.remove_words.settings', $words_remove)
->set('transformation_settings.remove_symbols.settings', $symbols_remove)
->set('transformation_settings.days_of_the_week.enabled', $values['days_of_the_week_enabled'])
->set('rebuild_items_per_batch', $values['rebuild_items_per_batch'])
->save();
$this
->messenger()
->addStatus($this
->t('The configuration options have been saved.'));
$this
->submitFormReindexOnly($form, $form_state);
}
/**
* Submission action for the "Rebuild Index" button.
*
* @param array $form
* The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
public function submitFormReindexOnly(array &$form, FormStateInterface $form_state) {
views_natural_sort_queue_data_for_rebuild();
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
ConfigurationForm:: |
protected | property | ||
ConfigurationForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
ConfigurationForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
ConfigurationForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
ConfigurationForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ConfigurationForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ConfigurationForm:: |
public | function | Submission action for the "Rebuild Index" button. | |
ConfigurationForm:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |
|
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. | |
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. |