]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Parse plugin parameters description with the PluginManager
authorArthurHoaro <arthur@hoa.ro>
Tue, 2 Aug 2016 09:02:20 +0000 (11:02 +0200)
committerArthurHoaro <arthur@hoa.ro>
Sat, 5 Nov 2016 13:29:52 +0000 (14:29 +0100)
Plugin parameter can contain a description in their meta file under the key:

    parameter.<param_name>="<description>"

application/PluginManager.php
application/config/ConfigPlugin.php
tests/PluginManagerTest.php
tests/config/ConfigPluginTest.php
tests/plugins/test/test.meta

index 1afc8d5c15da095952c472a1ee42c807792a7f68..1e132a7f652c78aa077a86ed3c1013ad58b7c95b 100644 (file)
@@ -185,7 +185,11 @@ class PluginManager
                     continue;
                 }
 
-                $metaData[$plugin]['parameters'][$param] = '';
+                $metaData[$plugin]['parameters'][$param]['value'] = '';
+                // Optional parameter description in parameter.PARAM_NAME=
+                if (isset($metaData[$plugin]['parameter.'. $param])) {
+                    $metaData[$plugin]['parameters'][$param]['desc'] = $metaData[$plugin]['parameter.'. $param];
+                }
             }
         }
 
index 047d2b03113320e1d3b0fba190376152cef5b75d..cb0b6fce439cd3b6a3367b968e96210df4e15c09 100644 (file)
@@ -80,9 +80,13 @@ function validate_plugin_order($formData)
 }
 
 /**
- * Affect plugin parameters values into plugins array.
+ * Affect plugin parameters values from the ConfigManager into plugins array.
  *
- * @param mixed $plugins Plugins array ($plugins[<plugin_name>]['parameters']['param_name'] = <value>.
+ * @param mixed $plugins Plugins array:
+ *                         $plugins[<plugin_name>]['parameters'][<param_name>] = [
+ *                                                                                 'value' => <value>,
+ *                                                                                 'desc' => <description>
+ *                                                                               ]
  * @param mixed $conf  Plugins configuration.
  *
  * @return mixed Updated $plugins array.
@@ -97,7 +101,7 @@ function load_plugin_parameter_values($plugins, $conf)
 
         foreach ($plugin['parameters'] as $key => $param) {
             if (!empty($conf[$key])) {
-                $out[$name]['parameters'][$key] = $conf[$key];
+                $out[$name]['parameters'][$key]['value'] = $conf[$key];
             }
         }
     }
index c751105132f80ea1cd233525fdc1e6c18fd7b260..ddf4818533a1777f422421feb29b44e7243a7afa 100644 (file)
@@ -79,8 +79,14 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase
         $this->pluginManager->load(array(self::$pluginName));
 
         $expectedParameters = array(
-            'pop' => '',
-            'hip' => '',
+            'pop' => array(
+                'value' => '',
+                'desc'  => 'pop description',
+            ),
+            'hip' => array(
+                'value' => '',
+                'desc' => '',
+            ),
         );
         $meta = $this->pluginManager->getPluginsMeta();
         $this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
index 716631b0d54a87d000ed123361711dbeda32dbc2..3b37cd7962cee974814872218277307258782420 100644 (file)
@@ -101,9 +101,9 @@ class ConfigPluginTest extends PHPUnit_Framework_TestCase
         $plugins = array(
             'plugin_name' => array(
                 'parameters' => array(
-                    'param1' => true,
-                    'param2' => false,
-                    'param3' => '',
+                    'param1' => array('value' => true),
+                    'param2' => array('value' => false),
+                    'param3' => array('value' => ''),
                 )
             )
         );
@@ -114,8 +114,8 @@ class ConfigPluginTest extends PHPUnit_Framework_TestCase
         );
 
         $result = load_plugin_parameter_values($plugins, $parameters);
-        $this->assertEquals('value1', $result['plugin_name']['parameters']['param1']);
-        $this->assertEquals('value2', $result['plugin_name']['parameters']['param2']);
-        $this->assertEquals('', $result['plugin_name']['parameters']['param3']);
+        $this->assertEquals('value1', $result['plugin_name']['parameters']['param1']['value']);
+        $this->assertEquals('value2', $result['plugin_name']['parameters']['param2']['value']);
+        $this->assertEquals('', $result['plugin_name']['parameters']['param3']['value']);
     }
 }
index ab999ed4c4c99c25e2f001a41cf7f2c8994a4706..26f243f0b65c44acf3ab4a8808ead1922a7a9889 100644 (file)
@@ -1,2 +1,4 @@
 description="test plugin"
-parameters="pop;hip"
\ No newline at end of file
+parameters="pop;hip"
+parameter.pop="pop description"
+parameter.hip=
\ No newline at end of file