SettingsForm.php in Hashtags 8
File
src/Form/SettingsForm.php
View source
<?php
namespace Drupal\hashtags\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class SettingsForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'hashtags.settings',
];
}
public function getFormId() {
return 'hashtags_settings_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
filter_formats_reset();
$config = $this
->config('hashtags.settings');
$form['hashtags_taxonomy_terms_field_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('"Hashtags taxonomy terms" field name'),
'#default_value' => $config
->get('hashtags_taxonomy_terms_field_name'),
'#required' => TRUE,
];
$form['hashtags_vid'] = [
'#type' => 'select',
'#title' => $this
->t('Hashtags vocabulary'),
'#options' => taxonomy_vocabulary_get_names(),
'#default_value' => $config
->get('hashtags_vid'),
'#required' => TRUE,
];
$form['hide_field_hashtags'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Hide hashtags field'),
'#default_value' => $config
->get('hide_field_hashtags'),
];
return parent::buildForm($form, $form_state);
}
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('hashtags.settings')
->set('hashtags_taxonomy_terms_field_name', $form_state
->getValue('hashtags_taxonomy_terms_field_name'))
->set('hashtags_vid', $form_state
->getValue('hashtags_vid'))
->set('hide_field_hashtags', $form_state
->getValue('hide_field_hashtags'))
->save();
parent::submitForm($form, $form_state);
}
}