|
5 | 5 | namespace Drupal\cmc\Form;
|
6 | 6 |
|
7 | 7 | use Drupal\Core\Form\ConfigFormBase;
|
| 8 | +use Drupal\Core\Form\ConfigTarget; |
8 | 9 | use Drupal\Core\Form\FormStateInterface;
|
9 | 10 |
|
10 | 11 | /**
|
@@ -41,40 +42,32 @@ public function buildForm(array $form, FormStateInterface $form_state) {
|
41 | 42 | 'errors' => $this->t('Display errors'),
|
42 | 43 | 'strict' => $this->t('Strict'),
|
43 | 44 | ],
|
44 |
| - '#default_value' => $config->get('operation_mode'), |
| 45 | + '#config_target' => 'cmc.settings:operation_mode', |
45 | 46 | ];
|
46 | 47 |
|
47 |
| - $form['front_end_only'] = [ |
| 48 | + $form['skip_admin'] = [ |
48 | 49 | '#type' => 'checkbox',
|
49 |
| - '#title' => $this->t('Check front-end only'), |
| 50 | + '#title' => $this->t('Skip admin pages'), |
50 | 51 | '#description' => $this->t('When enabled, cache tags will only be checked on pages using the default theme (front-end). When disabled, admin pages will be checked as well.'),
|
51 |
| - '#default_value' => $config->get('front_end_only'), |
| 52 | + '#config_target' => 'cmc.settings:skip_admin', |
52 | 53 | ];
|
53 | 54 |
|
54 | 55 | $form['skip_urls'] = [
|
55 | 56 | '#type' => 'textarea',
|
56 | 57 | '#title' => $this->t('Skip URLs'),
|
57 | 58 | '#description' => $this->t("A comma or new-line separated list of relative URLs that should not be checked."),
|
58 | 59 | '#default_value' => implode("\r\n", $config->get('skip_urls')),
|
| 60 | + '#config_target' => new ConfigTarget( |
| 61 | + 'cmc.settings', |
| 62 | + 'skip_urls', |
| 63 | + // Converts config value to a form value. |
| 64 | + fn($value) => implode("\r\n", $value), |
| 65 | + // Converts form value to a config value. |
| 66 | + fn($value) => array_map('trim', explode("\r\n", trim($value))), |
| 67 | + ), |
59 | 68 | ];
|
60 | 69 |
|
61 | 70 | return parent::buildForm($form, $form_state);
|
62 | 71 | }
|
63 | 72 |
|
64 |
| - /** |
65 |
| - * {@inheritdoc} |
66 |
| - */ |
67 |
| - public function submitForm(array &$form, FormStateInterface $form_state) { |
68 |
| - $skip_urls = preg_replace('/[\s, ]/', ',', $form_state->getValue('skip_urls')); |
69 |
| - $skip_urls = array_values(array_filter(explode(',', $skip_urls))); |
70 |
| - |
71 |
| - $this->config('cmc.settings') |
72 |
| - ->set('operation_mode', $form_state->getValue('operation_mode')) |
73 |
| - ->set('front_end_only', $form_state->getValue('front_end_only')) |
74 |
| - ->set('skip_urls', $skip_urls) |
75 |
| - ->save(); |
76 |
| - |
77 |
| - parent::submitForm($form, $form_state); |
78 |
| - } |
79 |
| - |
80 | 73 | }
|
0 commit comments