public function SynonymSettingsForm::buildForm in Search API Synonym 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ SynonymSettingsForm.php, line 70
Class
- SynonymSettingsForm
- Class SynonymSettingsForm.
Namespace
Drupal\search_api_synonym\FormCode
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);
}