ec06e3e2fd6a14b710c8399d6a68bae0403949fe
[yaffs-website] / web / modules / contrib / better_formats / src / Form / SettingsForm.php
1 <?php
2
3 namespace Drupal\better_formats\Form;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Class SettingsForm.
10  *
11  * @package Drupal\better_formats\Form
12  */
13 class SettingsForm extends ConfigFormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormId() {
19     return 'better_formats_settings_form';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function getEditableConfigNames() {
26     return ['better_formats.settings'];
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function buildForm(array $form, FormStateInterface $form_state) {
33     $config = $this->config('better_formats.settings');
34
35     $form['control'] = [
36       '#type' => 'fieldset',
37       '#title' => $this->t('Control'),
38     ];
39
40     $form['control']['per_field_core'] = [
41       '#type'  => 'checkbox',
42       '#title' => $this->t('Use field default'),
43       '#description' => $this->t('Use the core field module default value to set the default format. This will force the default format even when the default field value is empty. To set a default format you must re-edit a text field after saving it with the "Filtered text" option turned on.'),
44       '#default_value' => $config->get('per_field_core'),
45     ];
46
47     return parent::buildForm($form, $form_state);
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public function submitForm(array &$form, FormStateInterface $form_state) {
54     $config = $this->config('better_formats.settings');
55     $form_state->cleanValues();
56
57     foreach ($form_state->getValues() as $key => $value) {
58       $config->set($key, $value);
59     }
60     $config->save();
61
62     parent::submitForm($form, $form_state);
63   }
64
65 }