FlagSearchApiConfigForm.php in Flag Search API 8
File
src/Form/FlagSearchApiConfigForm.php
View source
<?php
namespace Drupal\flag_search_api\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class FlagSearchApiConfigForm extends ConfigFormBase {
public function getFormId() {
return 'flag_search_api_config_form';
}
protected function getEditableConfigNames() {
return [
'flag_search_api.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$chosen_conf = $this->configFactory
->get('flag_search_api.settings');
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Flag Search API Reindexing'),
);
$form['options']['reindex_on_flagging'] = array(
'#type' => 'checkbox',
'#title' => t('Reindex Item on Flagged action'),
'#default_value' => $chosen_conf
->get('reindex_on_flagging'),
'#description' => t('Enable or disable reindexing items on flagging action.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->configFactory
->getEditable('flag_search_api.settings');
$config
->set('reindex_on_flagging', $form_state
->getValue('reindex_on_flagging'));
$config
->save();
parent::submitForm($form, $form_state);
}
}