Browse code

Only build services config in consent configuration if any services selected.

Benjamin Roth authored on11/12/2019 22:43:09
Showing2 changed files
... ...
@@ -16,6 +16,7 @@ class TemplateListener
16 16
   {
17 17
     if (($rootPage = \PageModel::findByPk($GLOBALS['objPage']->rootId)) !== null && $rootPage->cookieconsent_enable)
18 18
     {
19
+      $Template = new \FrontendTemplate('cookieconsent');
19 20
       $arrServices = deserialize($rootPage->cookieconsent_services);
20 21
 
21 22
       $arrServiceConfiguration = array();
... ...
@@ -75,12 +76,10 @@ class TemplateListener
75 76
             ),
76 77
           );
77 78
         }
79
+        $Template->services = json_encode($arrServiceConfiguration);
78 80
       }
79 81
 
80
-      $Template = new \FrontendTemplate('cookieconsent');
81
-
82 82
       $Template->privacy_policy_link = $rootPage->cookieconsent_link != '' ? "'".$rootPage->cookieconsent_link."'" : "null";
83
-      $Template->services = json_encode($arrServiceConfiguration);
84 83
 
85 84
       if (strpos($strBuffer, '<head>'))
86 85
       {
... ...
@@ -95,10 +95,10 @@
95 95
           }
96 96
         }
97 97
       }
98
-    },
98
+    }<?php if ($this->services): ?>,
99 99
     // List actual services here
100 100
     services: {
101 101
       <?= $this->services ?>
102
-    }
102
+    }<?php endif; ?>
103 103
   });
104 104
 </script>
105 105
\ No newline at end of file