From 38ab59e34a74fd99534b7d3d8751a7efcb28f245 Mon Sep 17 00:00:00 2001
From: Ankit Kumar <krankitjha@gmail.com>
Date: Tue, 8 Apr 2025 22:27:11 +0530
Subject: [PATCH 1/7] Valid config and update how configuration is saved

---
 src/Form/AdminSettingsForm.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/Form/AdminSettingsForm.php b/src/Form/AdminSettingsForm.php
index 28cb6ec..248b766 100644
--- a/src/Form/AdminSettingsForm.php
+++ b/src/Form/AdminSettingsForm.php
@@ -31,6 +31,7 @@ class AdminSettingsForm extends ConfigFormBase {
    */
   public function buildForm(array $form, FormStateInterface $form_state): array {
     $config = $this->config('cacheexclude.settings');
+    $selected_types = $config->get('cacheexclude_node_types') ?? [];
 
     $form['cacheexclude_list'] = [
       '#type' => 'textarea',
@@ -46,7 +47,7 @@ class AdminSettingsForm extends ConfigFormBase {
     $form['cacheexclude_node_types'] = [
       '#type' => 'checkboxes',
       '#title' => t('Content types to exclude from caching'),
-      '#default_value' => !is_null($config->get('cacheexclude_node_types')) ? $config->get('cacheexclude_node_types') : [],
+      '#default_value' => array_combine($selected_types, $selected_types),
       '#options' => node_type_get_names(),
       '#description' => $this->t("Check all content types that you do not want to be cached."),
     ];
@@ -62,8 +63,10 @@ class AdminSettingsForm extends ConfigFormBase {
     drupal_flush_all_caches();
 
     $config = $this->configFactory->getEditable('cacheexclude.settings');
+    $values = $form_state->getValue('cacheexclude_node_types');
+    $enabled = array_keys(array_filter($values));
     $config->set('cacheexclude_list', $form_state->getValue('cacheexclude_list'))->save();
-    $config->set('cacheexclude_node_types', $form_state->getValue('cacheexclude_node_types'))->save();
+    $config->set('cacheexclude_node_types', $enabled)->save();
     parent::submitForm($form, $form_state);
   }
 
-- 
GitLab


From 2f48b15d315a7f9bd0be1d466393bc52315fffba Mon Sep 17 00:00:00 2001
From: Ankit Kumar <krankitjha@gmail.com>
Date: Thu, 10 Apr 2025 17:09:18 +0530
Subject: [PATCH 2/7] added update hook

---
 cacheexclude.install | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 cacheexclude.install

diff --git a/cacheexclude.install b/cacheexclude.install
new file mode 100644
index 0000000..7e9d4b7
--- /dev/null
+++ b/cacheexclude.install
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * @file
+ * Install, update and uninstall functions for the Cache Exclude module.
+ *
+ * @see cacheexclude.install
+ */
+
+ function cacheexclude_update_8101() {
+  $config = \Drupal::configFactory()->getEditable('cacheexclude.settings');
+  $types = $config->get('cacheexclude_node_types');
+  if (is_array($types)) {
+    $filtered = array_keys(array_filter($types));
+    $config->set('cacheexclude_node_types', $filtered)->save();
+  }
+}
-- 
GitLab


From c5108dd50c6a521a39bed5b2ee53e01cca49dccf Mon Sep 17 00:00:00 2001
From: Ankit Kumar <65638-Ankit_K@users.noreply.drupalcode.org>
Date: Mon, 14 Apr 2025 14:05:18 +0000
Subject: [PATCH 3/7] Update file cacheexclude.install

---
 cacheexclude.install | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cacheexclude.install b/cacheexclude.install
index 7e9d4b7..c3df941 100644
--- a/cacheexclude.install
+++ b/cacheexclude.install
@@ -7,7 +7,7 @@
  * @see cacheexclude.install
  */
 
- function cacheexclude_update_8101() {
+ function cacheexclude_update_21001() {
   $config = \Drupal::configFactory()->getEditable('cacheexclude.settings');
   $types = $config->get('cacheexclude_node_types');
   if (is_array($types)) {
-- 
GitLab


From 8fd04df8f9a2313893cbcbd25f55c916a196c7eb Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Fri, 18 Apr 2025 12:41:11 -0400
Subject: [PATCH 4/7] Schema update

---
 cacheexclude.install                     | 5 ++++-
 cacheexclude.links.menu.yml              | 2 +-
 config/install/cacheexclude.settings.yml | 2 ++
 config/schema/cacheexclude.schema.yml    | 4 ++++
 4 files changed, 11 insertions(+), 2 deletions(-)
 create mode 100644 config/install/cacheexclude.settings.yml

diff --git a/cacheexclude.install b/cacheexclude.install
index c3df941..1c2b1e4 100644
--- a/cacheexclude.install
+++ b/cacheexclude.install
@@ -7,7 +7,10 @@
  * @see cacheexclude.install
  */
 
- function cacheexclude_update_21001() {
+/**
+ * Fix config keys.
+ */
+function cacheexclude_update_21001(): void {
   $config = \Drupal::configFactory()->getEditable('cacheexclude.settings');
   $types = $config->get('cacheexclude_node_types');
   if (is_array($types)) {
diff --git a/cacheexclude.links.menu.yml b/cacheexclude.links.menu.yml
index b285bd3..02ccd64 100644
--- a/cacheexclude.links.menu.yml
+++ b/cacheexclude.links.menu.yml
@@ -1,5 +1,5 @@
 cacheexclude.settings:
-  title: 'Cacheexclude settings'
+  title: 'Cache exclude settings'
   description: 'Manage Cache Exclude settings for your site.'
   parent: system.admin_config_system
   route_name: cacheexclude.settings
diff --git a/config/install/cacheexclude.settings.yml b/config/install/cacheexclude.settings.yml
new file mode 100644
index 0000000..a05c1e5
--- /dev/null
+++ b/config/install/cacheexclude.settings.yml
@@ -0,0 +1,2 @@
+cacheexclude_list: ''
+cacheexclude_node_types: {  }
diff --git a/config/schema/cacheexclude.schema.yml b/config/schema/cacheexclude.schema.yml
index 559a638..7ec44a3 100644
--- a/config/schema/cacheexclude.schema.yml
+++ b/config/schema/cacheexclude.schema.yml
@@ -1,6 +1,8 @@
 cacheexclude.settings:
   type: config_object
   label: 'Cache exclude settings'
+  constraints:
+    FullyValidatable: ~
   mapping:
     cacheexclude_list:
       type: string
@@ -11,3 +13,5 @@ cacheexclude.settings:
       sequence:
         type: string
         label: 'Node types'
+        constraints:
+          EntityBundleExists: node
-- 
GitLab


From cd9eca93b16974406913e25bf6292c18648ab12d Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Fri, 18 Apr 2025 12:46:36 -0400
Subject: [PATCH 5/7] Test fix

---
 tests/src/Kernel/CacheExcludeMigrateTest.php | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/tests/src/Kernel/CacheExcludeMigrateTest.php b/tests/src/Kernel/CacheExcludeMigrateTest.php
index e26db06..b9320b5 100644
--- a/tests/src/Kernel/CacheExcludeMigrateTest.php
+++ b/tests/src/Kernel/CacheExcludeMigrateTest.php
@@ -59,11 +59,9 @@ class CacheExcludeMigrateTest extends MigrateDrupal7TestBase {
       'cacheexclude_list' => '/node/3
 /blog/*',
       'cacheexclude_node_types' => [
-        'range' => 'range',
-        'test_display' => 'test_display',
-        'video' => 'video',
-        'article' => '0',
-        'page' => '0',
+        'range',
+        'test_display',
+        'video',
       ],
     ];
     $config = $this->config('cacheexclude.settings')->getRawData();
-- 
GitLab


From 6e8e4e129a1951936b6201555cd262234c8127ca Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Fri, 18 Apr 2025 13:04:51 -0400
Subject: [PATCH 6/7] Fix migration tests

---
 src/Plugin/migrate/process/CacheexcludeNodes.php | 2 +-
 tests/src/Kernel/CacheExcludeMigrateTest.php     | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/Plugin/migrate/process/CacheexcludeNodes.php b/src/Plugin/migrate/process/CacheexcludeNodes.php
index 36b4ff2..3812855 100644
--- a/src/Plugin/migrate/process/CacheexcludeNodes.php
+++ b/src/Plugin/migrate/process/CacheexcludeNodes.php
@@ -58,7 +58,7 @@ class CacheexcludeNodes extends ProcessPluginBase implements ContainerFactoryPlu
       $destination_node_type = $lookup_result[0]['type'];
       $node_types[$destination_node_type] = $data ? $destination_node_type : 0;
     }
-    return $node_types;
+    return array_keys(array_filter($node_types));
   }
 
 }
diff --git a/tests/src/Kernel/CacheExcludeMigrateTest.php b/tests/src/Kernel/CacheExcludeMigrateTest.php
index b9320b5..fde8764 100644
--- a/tests/src/Kernel/CacheExcludeMigrateTest.php
+++ b/tests/src/Kernel/CacheExcludeMigrateTest.php
@@ -65,6 +65,7 @@ class CacheExcludeMigrateTest extends MigrateDrupal7TestBase {
       ],
     ];
     $config = $this->config('cacheexclude.settings')->getRawData();
+    unset($config['_core']);
     $this->assertSame($expected_config, $config);
   }
 
-- 
GitLab


From 4d792d0b8ecd21030e6ff3150347b15bf7939f86 Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Fri, 18 Apr 2025 13:24:02 -0400
Subject: [PATCH 7/7] Fix tests now that there is default config

---
 src/EventSubscriber/CacheexcludeSubscriber.php | 4 ++--
 src/Form/AdminSettingsForm.php                 | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/EventSubscriber/CacheexcludeSubscriber.php b/src/EventSubscriber/CacheexcludeSubscriber.php
index b2f2b14..4453e51 100644
--- a/src/EventSubscriber/CacheexcludeSubscriber.php
+++ b/src/EventSubscriber/CacheexcludeSubscriber.php
@@ -75,7 +75,7 @@ class CacheexcludeSubscriber implements EventSubscriberInterface {
     $config = $this->configFactory->get('cacheexclude.settings');
     $node_types = $config->get('cacheexclude_node_types');
 
-    if (!is_null($node_types)) {
+    if (!empty($node_types)) {
       $node_types = array_filter($node_types);
       if (isset($node_type) && in_array($node_type, $node_types, TRUE)) {
         // Disable page cache temporarily.
@@ -94,7 +94,7 @@ class CacheexcludeSubscriber implements EventSubscriberInterface {
     // Get cacheexclude page configuration.
     $config = $this->configFactory->get('cacheexclude.settings');
     // Only trim if config exists.
-    $pages = !is_null($config->get('cacheexclude_list')) ? trim($config->get('cacheexclude_list')) : NULL;
+    $pages = !empty($config->get('cacheexclude_list')) ? trim($config->get('cacheexclude_list')) : NULL;
 
     // If the current page is one we want to exclude from the cache,
     // disable page cache temporarily.
diff --git a/src/Form/AdminSettingsForm.php b/src/Form/AdminSettingsForm.php
index 248b766..1acebd6 100644
--- a/src/Form/AdminSettingsForm.php
+++ b/src/Form/AdminSettingsForm.php
@@ -35,7 +35,7 @@ class AdminSettingsForm extends ConfigFormBase {
 
     $form['cacheexclude_list'] = [
       '#type' => 'textarea',
-      '#title' => t('Pages to exclude from caching'),
+      '#title' => $this->t('Pages to exclude from caching'),
       '#default_value' => $config->get('cacheexclude_list'),
       '#width' => 40,
       '#height' => 10,
@@ -46,7 +46,7 @@ class AdminSettingsForm extends ConfigFormBase {
 
     $form['cacheexclude_node_types'] = [
       '#type' => 'checkboxes',
-      '#title' => t('Content types to exclude from caching'),
+      '#title' => $this->t('Content types to exclude from caching'),
       '#default_value' => array_combine($selected_types, $selected_types),
       '#options' => node_type_get_names(),
       '#description' => $this->t("Check all content types that you do not want to be cached."),
-- 
GitLab