Fixed the compilation of styles when editing them
authorAlexander Ebert <ebert@woltlab.com>
Mon, 17 Apr 2023 12:09:26 +0000 (14:09 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 17 Apr 2023 12:09:26 +0000 (14:09 +0200)
Fixes #5376

wcfsetup/install/files/lib/acp/form/StyleEditForm.class.php

index 7bfe127ba9b59b1457ac82cf7901822960fe2710..07b6e61bd4b1acbd357e24c7df1df41406059054 100644 (file)
@@ -80,7 +80,29 @@ class StyleEditForm extends StyleAddForm
      */
     public function validateIndividualScss()
     {
-        $variables = $this->variables;
+        // If the style has a dark mode then `$variables` contains either the
+        // values for the “light” theme or the dark variant. It is necessary to
+        // inject the complementary values, otherwise the compiled style is
+        // incomplete and causes issue when the file is being promoted to be
+        // the actual stylesheet when saving.
+        if ($this->style->hasDarkMode) {
+            $variables = $this->style->getVariables();
+            if ($this->isDarkMode) {
+                foreach ($this->variables as $key => $value) {
+                    $variableName = Style::DARK_MODE_PREFIX . $key;
+                    if (isset($variables[$variableName])) {
+                        $variables[$variableName] = $value;
+                    }
+                }
+            } else {
+                foreach ($this->variables as $key => $value) {
+                    $variables[$key] = $value;
+                }
+            }
+        } else {
+            $variables = $this->variables;
+        }
+
         if (!$this->style->isTainted) {
             $variables['individualScss'] = Style::joinLessVariables(
                 $variables['individualScss'],