Improve the filter for variables with a dark mode variant
authorAlexander Ebert <ebert@woltlab.com>
Mon, 17 Apr 2023 15:06:42 +0000 (17:06 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 17 Apr 2023 15:06:42 +0000 (17:06 +0200)
wcfsetup/install/files/lib/acp/form/StyleEditForm.class.php

index 76b2eb8879c034c12bbf06822e4558eb5d9a5db4..05429c2db4a1189c273fd58e2ff451354ff8763d 100644 (file)
@@ -87,17 +87,14 @@ class StyleEditForm extends StyleAddForm
         // the actual stylesheet when saving.
         if ($this->style->hasDarkMode) {
             $variables = $this->style->getVariables();
+            $supportsDarkMode = $this->getVariablesWithDarkModeSupport();
             if ($this->isDarkMode) {
                 foreach ($this->variables as $key => $value) {
-                    $variableName = Style::DARK_MODE_PREFIX . $key;
-                    if (isset($variables[$variableName])) {
-                        $variables[$variableName] = $value;
-                    } else {
-                        // Some values are shared between both color schemes
-                        // such as font sizes. These values are always present
-                        // regardless of the active color schemes.
-                        $variables[$key] = $value;
+                    if (\in_array($key, $supportsDarkMode, true)) {
+                        $key = Style::DARK_MODE_PREFIX . $key;
                     }
+
+                    $variables[$key] = $value;
                 }
             } else {
                 foreach ($this->variables as $key => $value) {
@@ -152,6 +149,21 @@ class StyleEditForm extends StyleAddForm
         }
     }
 
+    /**
+     * @since 6.0
+     * @return string[]
+     */
+    private function getVariablesWithDarkModeSupport(): array
+    {
+        $sql = "SELECT  variableName
+                FROM    wcf1_style_variable
+                WHERE   defaultValueDarkMode IS NOT NULL";
+        $statement = WCF::getDB()->prepare($sql);
+        $statement->execute();
+
+        return $statement->fetchAll(\PDO::FETCH_COLUMN);
+    }
+
     /**
      * @inheritDoc
      */