View source
<?php
namespace Drupal\asaf\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
class AsafSettingsForm extends ConfigFormBase {
public function getFormId() {
return 'asaf_settings_form';
}
protected function getEditableConfigNames() {
return [
'asaf_settings.config',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$asaf_config = $this
->config('asaf_settings.config');
$form['asaf_forms'] = array(
'#type' => 'textarea',
'#title' => t('Forms'),
'#description' => t('A list of form IDs. One form ID per line. Also, you can specify buttons which should be handled (for eaxmple: article_node_form@save+preview) or buttons which shouldn\'t be handled (article_node_form@-delete).'),
'#default_value' => $asaf_config
->get('asaf_forms', 'asaf_admin_settings_form'),
);
$form['asaf_show_form_ids'] = array(
'#type' => 'checkbox',
'#title' => t('Show form ids'),
'#description' => t('Will show a list of form IDs present on the particular page. <strong>Be careful, because all users (including anonymous) will see a debug messages when this option is enabled.</strong>'),
'#default_value' => $asaf_config
->get('asaf_show_form_ids', 0),
);
$form['experimental'] = array(
'#type' => 'fieldset',
'#title' => t('Experimental'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['experimental']['asaf_autoload_form_stuff'] = array(
'#type' => 'checkbox',
'#title' => t('Autoload forms stuff'),
'#description' => t('It can help in some seldom cases when you try to ajaxify form and retrieve "Call to undefined function..." error.'),
'#default_value' => $asaf_config
->get('asaf_autoload_form_stuff', FALSE),
);
$form['experimental']['asaf_form_submit_by_enter'] = array(
'#type' => 'checkbox',
'#title' => t('Submit form by \'enter\' button'),
'#default_value' => $asaf_config
->get('asaf_form_submit_by_enter', FALSE),
);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('asaf_settings.config')
->set('asaf_forms', $form_state
->getValue('asaf_forms'))
->set('asaf_show_form_ids', $form_state
->getValue('asaf_show_form_ids'))
->set('asaf_autoload_form_stuff', $form_state
->getValue('asaf_autoload_form_stuff'))
->set('asaf_form_submit_by_enter', $form_state
->getValue('asaf_form_submit_by_enter'))
->save();
parent::submitForm($form, $form_state);
}
}