]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - plugins/default_colors/default_colors.php
Fix default_colors plugin: update CSS file on color change
[github/shaarli/Shaarli.git] / plugins / default_colors / default_colors.php
index e1fd5cfbdb19daf547519af2d7f41482c88f7b96..d3e1fa761a86501127bad13a985c42c6f45540ae 100644 (file)
@@ -28,14 +28,14 @@ function default_colors_init($conf)
 {
     $params = [];
     foreach (DEFAULT_COLORS_PLACEHOLDERS as $placeholder) {
-        $value = trim($conf->get('plugins.'. $placeholder, ''));
+        $value = trim($conf->get('plugins.' . $placeholder, ''));
         if (strlen($value) > 0) {
             $params[$placeholder] = $value;
         }
     }
 
     if (empty($params)) {
-        $error = t('Default colors plugin error: '.
+        $error = t('Default colors plugin error: ' .
             'This plugin is active and no custom color is configured.');
         return [$error];
     }
@@ -46,6 +46,20 @@ function default_colors_init($conf)
     }
 }
 
+/**
+ * When plugin parameters are saved, we regenerate the custom CSS file with provided settings.
+ *
+ * @param array         $data $_POST array
+ *
+ * @return array Updated $_POST array
+ */
+function hook_default_colors_save_plugin_parameters($data)
+{
+    default_colors_generate_css_file($data);
+
+    return $data;
+}
+
 /**
  * When linklist is displayed, include default_colors CSS file.
  *
@@ -56,7 +70,7 @@ function default_colors_init($conf)
 function hook_default_colors_render_includes($data)
 {
     $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css';
-    if (file_exists($file )) {
+    if (file_exists($file)) {
         $data['css_files'][] = $file ;
     }
 
@@ -75,7 +89,7 @@ function default_colors_generate_css_file($params): void
     $content = '';
     foreach (DEFAULT_COLORS_PLACEHOLDERS as $rule) {
         $content .= !empty($params[$rule])
-            ? default_colors_format_css_rule($params, $rule) .';'. PHP_EOL
+            ? default_colors_format_css_rule($params, $rule) . ';' . PHP_EOL
             : '';
     }
 
@@ -99,8 +113,8 @@ function default_colors_format_css_rule($data, $parameter)
     }
 
     $key = str_replace('DEFAULT_COLORS_', '', $parameter);
-    $key = str_replace('_', '-', strtolower($key)) .'-color';
-    return '  --'. $key .': '. $data[$parameter];
+    $key = str_replace('_', '-', strtolower($key)) . '-color';
+    return '  --' . $key . ': ' . $data[$parameter];
 }