Make addNodeParams() driver-specific
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 23 Aug 2010 22:00:25 +0000 (16:00 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 24 Aug 2010 06:00:58 +0000 (00:00 -0600)
framework/Tree/lib/Horde/Tree.php
framework/Tree/lib/Horde/Tree/Html.php
framework/Tree/lib/Horde/Tree/Select.php

index 2abef21..eecbead 100644 (file)
@@ -26,6 +26,13 @@ class Horde_Tree implements Countable
     const TOGGLE = 'ht_toggle_';
 
     /**
+     * Allowed parameters for nodes.
+     *
+     * @var array
+     */
+    protected $_allowed = array();
+
+    /**
      * The name of this instance.
      *
      * @var string
@@ -318,18 +325,7 @@ class Horde_Tree implements Countable
      * Adds additional parameters to a node.
      *
      * @param string $id     The unique node id.
-     * @param array $params  Any other parameters to set.
-     * <pre>
-     * class - CSS class to use with this node
-     * icon - Icon to display next node
-     * iconalt - Alt text to use for the icon
-     * iconopen - Icon to indicate this node as expanded
-     * onclick - Onclick event attached to this node
-     * url - URL to link the node to
-     * urlclass - CSS class for the node's URL
-     * title - Link tooltip title
-     * target - Target for the 'url' link
-     * </pre>
+     * @param array $params  Parameters to set (key/value pairs).
      */
     public function addNodeParams($id, $params = array())
     {
@@ -339,17 +335,12 @@ class Horde_Tree implements Countable
             $params = array($params);
         }
 
-        $allowed = array(
-            'class', 'icon', 'iconalt', 'iconopen',
-            'onclick', 'url', 'urlclass', 'title', 'target',
-        );
-
-        foreach ($params as $param_id => $param_val) {
+        foreach ($params as $p_id => $p_val) {
             // Set only allowed and non-null params.
-            if (in_array($param_id, $allowed) && !is_null($param_val)) {
-                $this->_nodes[$id][$param_id] = is_object($param_val)
-                    ? strval($param_val)
-                    : $param_val;
+            if (!is_null($p_val) && in_array($p_id, $this->_allowed)) {
+                $this->_nodes[$id][$p_id] = is_object($p_val)
+                    ? strval($p_val)
+                    : $p_val;
             }
         }
     }
index 65f9023..587bfe9 100644 (file)
@@ -44,6 +44,23 @@ class Horde_Tree_Html extends Horde_Tree
     protected $_alt_count = 0;
 
     /**
+     * Allowed parameters for nodes.
+     *
+     * @var array
+     */
+    protected $_allowed = array(
+        'class',
+        'icon',
+        'iconalt',
+        'iconopen',
+        'onclick',
+        'url',
+        'urlclass',
+        'title',
+        'target'
+    );
+
+    /**
      * Images array.
      *
      * @var array
index dfa5257..086ffa2 100644 (file)
 class Horde_Tree_Select extends Horde_Tree
 {
     /**
-     * Node list.
+     * Allowed parameters for nodes.
      *
      * @var array
      */
-    protected $_nodes = array();
+    protected $_allowed = array(
+        'selected'
+    );
 
     /**
      * Should the tree be rendered statically?
@@ -50,27 +52,14 @@ class Horde_Tree_Select extends Horde_Tree
      * Adds additional parameters to a node.
      *
      * @param string $id     The unique node id.
-     * @param array $params  Any other parameters to set.
+     * @param array $params  Parameters to set (key/value pairs).
      * <pre>
      * selected - (boolean) Whether this node is selected.
      * </pre>
      */
     public function addNodeParams($id, $params = array())
     {
-        $id = $this->_nodeId($id);
-
-        if (!is_array($params)) {
-            $params = array($params);
-        }
-
-        $allowed = array('selected');
-
-        foreach ($params as $param_id => $param_val) {
-            /* Set only allowed and non-null params. */
-            if (in_array($param_id, $allowed) && !is_null($param_val)) {
-                $this->_nodes[$id][$param_id] = $param_val;
-            }
-        }
+        parent::addNodeParams($id, $params);
     }
 
     /**