Skip to content

Commit 34b46fa

Browse files
committed
Code review feedback 1
1 parent 1f30d30 commit 34b46fa

File tree

6 files changed

+20
-28
lines changed

6 files changed

+20
-28
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Visit `/admin/config/development/cmc` to configure the module. The following opt
2424
- **Display errors**: Shows missing cache tags at the top of affected pages
2525
- **Strict**: Throws exceptions when cache tags are missing (recommended for development)
2626

27-
### Front-end Only
27+
### Skip Admin Pages
2828

2929
When enabled (default), the module only checks pages using the default theme. When disabled, it also checks admin pages using the admin theme.
3030

cmc.links.menu.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ cmc.settings:
33
description: 'Configure Cacheability Metadata Checker settings.'
44
parent: system.admin_config_development
55
route_name: cmc.settings
6-
weight: 100

config/install/cmc.settings.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
operation_mode: 'disabled'
2-
front_end_only: true
2+
skip_admin: true
33
skip_urls: []

config/schema/cmc.schema.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ cmc.settings:
1010
- disabled
1111
- errors
1212
- strict
13-
front_end_only:
13+
skip_admin:
1414
type: boolean
15-
label: 'Check front-end only'
15+
label: 'Skip admin pages'
1616
skip_urls:
1717
label: URLs to be skipped
1818
type: sequence

src/EventSubscriber/LoadedEntitySubscriber.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public function onResponse(ResponseEvent $responseEvent) {
111111

112112
// Skip checking if this is an admin page and the config is set to only
113113
// check front-end pages.
114-
$only_front_end = $this->config->get('front_end_only') ?? TRUE;
115-
if ($only_front_end) {
114+
$skip_admin = $this->config->get('skip_admin') ?? TRUE;
115+
if ($skip_admin) {
116116
$active_theme = $this->themeManager->getActiveTheme()->getName();
117117
$admin_theme = $this->configFactory->get('system.theme')->get('admin');
118118
if ($active_theme === $admin_theme) {
@@ -136,7 +136,7 @@ public function onResponse(ResponseEvent $responseEvent) {
136136
// Never fail hard on our own config page to avoid smart users locking
137137
// themselves out of the house.
138138
if ($operation_mode === 'strict' &&
139-
!$only_front_end &&
139+
!$skip_admin &&
140140
$this->routeMatch->getRouteName() === 'cmc.settings') {
141141
return;
142142
}

src/Form/CmcSettingsForm.php

+13-20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Drupal\cmc\Form;
66

77
use Drupal\Core\Form\ConfigFormBase;
8+
use Drupal\Core\Form\ConfigTarget;
89
use Drupal\Core\Form\FormStateInterface;
910

1011
/**
@@ -41,40 +42,32 @@ public function buildForm(array $form, FormStateInterface $form_state) {
4142
'errors' => $this->t('Display errors'),
4243
'strict' => $this->t('Strict'),
4344
],
44-
'#default_value' => $config->get('operation_mode'),
45+
'#config_target' => 'cmc.settings:operation_mode',
4546
];
4647

47-
$form['front_end_only'] = [
48+
$form['skip_admin'] = [
4849
'#type' => 'checkbox',
49-
'#title' => $this->t('Check front-end only'),
50+
'#title' => $this->t('Skip admin pages'),
5051
'#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',
5253
];
5354

5455
$form['skip_urls'] = [
5556
'#type' => 'textarea',
5657
'#title' => $this->t('Skip URLs'),
5758
'#description' => $this->t("A comma or new-line separated list of relative URLs that should not be checked."),
5859
'#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+
),
5968
];
6069

6170
return parent::buildForm($form, $form_state);
6271
}
6372

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-
8073
}

0 commit comments

Comments
 (0)