class SynonymSettingsForm in Search API Synonym 8
Class SynonymSettingsForm.
@package Drupal\search_api_synonym\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\search_api_synonym\Form\SynonymSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SynonymSettingsForm
1 string reference to 'SynonymSettingsForm'
File
- src/
Form/ SynonymSettingsForm.php, line 18
Namespace
Drupal\search_api_synonym\FormView source
class SynonymSettingsForm extends ConfigFormBase {
/**
* An array containing available export plugins.
*
* @var array
*/
protected $availablePlugins = [];
/**
* Constructs a VacancySourceForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\search_api_synonym\Export\ExportPluginManager $manager
* The synonyms export plugin manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, ExportPluginManager $manager) {
parent::__construct($config_factory);
foreach ($manager
->getAvailableExportPlugins() as $id => $definition) {
$this->availablePlugins[$id] = $manager
->createInstance($id);
}
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('plugin.manager.search_api_synonym.export'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'search_api_synonym_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'search_api_synonym.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config($this
->getEditableConfigNames()[0]);
// Add cron settings
$cron = $config
->get('cron');
$options = [];
foreach ($this->availablePlugins as $id => $source) {
$definition = $source
->getPluginDefinition();
$options[$id] = $definition['label'];
}
$intervals = [
0,
900,
1800,
3600,
10800,
21600,
43200,
86400,
604800,
];
$intervals = array_combine($intervals, $intervals);
$intervals = array_map([
\Drupal::service('date.formatter'),
'formatInterval',
], $intervals);
$intervals[0] = t('Never');
$form['interval'] = [
'#type' => 'select',
'#title' => $this
->t('Export synonyms every'),
'#description' => $this
->t('How often should Drupal export synonyms?'),
'#default_value' => isset($cron['interval']) ? $cron['interval'] : 86400,
'#options' => $intervals,
];
$form['cron'] = [
'#title' => $this
->t('Cron settings'),
'#type' => 'details',
'#open' => TRUE,
'#tree' => TRUE,
'#states' => array(
'invisible' => array(
':input[name="interval"]' => array(
'value' => 0,
),
),
),
];
$form['cron']['plugin'] = [
'#type' => 'select',
'#title' => $this
->t('Synonym export plugin'),
'#description' => $this
->t('Select the export plugin being used by cron.'),
'#default_value' => $cron['plugin'] ? $cron['plugin'] : '',
'#options' => $options,
];
$form['cron']['type'] = [
'#type' => 'radios',
'#title' => $this
->t('Type'),
'#description' => $this
->t('Which synonym type should be exported by cron?'),
'#default_value' => $cron['type'] ? $cron['type'] : 'all',
'#options' => [
'all' => $this
->t('All'),
'synonym' => $this
->t('Synonyms'),
'spelling_error' => $this
->t('Spelling errors'),
],
];
$form['cron']['filter'] = [
'#type' => 'radios',
'#title' => $this
->t('Filter'),
'#description' => $this
->t('Which filters should be used when selecting synonyms.'),
'#default_value' => $cron['filter'] ? $cron['filter'] : 'none',
'#options' => [
'none' => $this
->t('No filter'),
'nospace' => $this
->t('Synonyms without spaces in the word'),
'onlyspace' => $this
->t('Synonyms with spaces in the word'),
],
];
$form['cron']['separate_files'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Separate files'),
'#description' => $this
->t('Export synonyms with and without spaces into separate files.'),
'#default_value' => $cron['separate_files'] ? $cron['separate_files'] : '',
'#states' => [
'visible' => [
':radio[name="cron[filter]"]' => [
'value' => 'none',
],
],
],
];
$form['cron']['export_if_changed'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Only export if changes'),
'#description' => $this
->t('Only export synonyms if their is either new or changed synonyms since last export.'),
'#default_value' => $cron['export_if_changed'] ? $cron['export_if_changed'] : FALSE,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValue('cron');
$values['interval'] = $form_state
->getValue('interval');
$this
->config($this
->getEditableConfigNames()[0])
->set('cron', $values)
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
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. | |
SynonymSettingsForm:: |
protected | property | An array containing available export plugins. | |
SynonymSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SynonymSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SynonymSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SynonymSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SynonymSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SynonymSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
SynonymSettingsForm:: |
public | function |
Constructs a VacancySourceForm object. 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. |