Index: library/Zend/Navigation/Page.php =================================================================== --- library/Zend/Navigation/Page.php (revision 24695) +++ library/Zend/Navigation/Page.php (working copy) @@ -163,6 +163,13 @@ protected $_properties = array(); /** + * Custom HTML attributes + * + * @var array + */ + protected $_customHtmlAttribs = array(); + + /** * The type of page to use when it wasn't set * * @var string @@ -666,6 +673,119 @@ } /** + * Sets a single custom HTML attribute + * + * @param string $name name of the HTML attribute + * @param string|null $value value for the HTML attribute + * @return Zend_Navigation_Page fluent interface, returns self + * @throws Zend_Navigation_Exception if name is not string or value is + * not null or a string + */ + public function setCustomHtmlAttrib($name, $value) + { + if (!is_string($name)) { + require_once 'Zend/Navigation/Exception.php'; + throw new Zend_Navigation_Exception( + 'Invalid argument: $name must be a string' + ); + } + + if (null !== $value && !is_string($value)) { + require_once 'Zend/Navigation/Exception.php'; + throw new Zend_Navigation_Exception( + 'Invalid argument: $value must be a string or null' + ); + } + + if (null === $value && isset($this->_customHtmlAttribs[$name])) { + unset($this->_customHtmlAttribs[$name]); + } else { + $this->_customHtmlAttribs[$name] = $value; + } + + return $this; + } + + /** + * Returns a single custom HTML attributes by name + * + * @param string $name name of the HTML attribute + * @return string|null value for the HTML attribute or null + * @throws Zend_Navigation_Exception if name is not string + */ + public function getCustomHtmlAttrib($name) + { + if (!is_string($name)) { + require_once 'Zend/Navigation/Exception.php'; + throw new Zend_Navigation_Exception( + 'Invalid argument: $name must be a string' + ); + } + + if (isset($this->_customHtmlAttribs[$name])) { + return $this->_customHtmlAttribs[$name]; + } + + return null; + } + + /** + * Sets multiple custom HTML attributes at once + * + * @param array $attribs an associative array of html attributes + * @return Zend_Navigation_Page fluent interface, returns self + */ + public function setCustomHtmlAttribs(array $attribs) + { + foreach ($attribs as $key => $value) { + $this->setCustomHtmlAttrib($key, $value); + } + return $this; + } + + /** + * Returns all custom HTML attributes as an array + * + * @return array an array containing custom HTML attributes + */ + public function getCustomHtmlAttribs() + { + return $this->_customHtmlAttribs; + } + + /** + * Removes a custom HTML attribute from the page + * + * @param string $name name of the custom HTML attribute + * @return Zend_Navigation_Page fluent interface, returns self + */ + public function removeCustomHtmlAttrib($name) + { + if (!is_string($name)) { + require_once 'Zend/Navigation/Exception.php'; + throw new Zend_Navigation_Exception( + 'Invalid argument: $name must be a string' + ); + } + + if (isset($this->_customHtmlAttribs[$name])) { + unset($this->_customHtmlAttribs[$name]); + } + } + + /** + * Clear all custom HTML attributes + * + * @return Zend_Navigation_Page fluent interface, returns self + */ + public function clearCustomHtmlAttribs() + { + $this->_customHtmlAttribs = array(); + + return $this; + } + + /** * Sets page order to use in parent container * * @param int $order [optional] page order in container. @@ -1182,23 +1302,25 @@ return array_merge( $this->getCustomProperties(), array( - 'label' => $this->getlabel(), - 'fragment' => $this->getFragment(), - 'id' => $this->getId(), - 'class' => $this->getClass(), - 'title' => $this->getTitle(), - 'target' => $this->getTarget(), - 'accesskey' => $this->getAccesskey(), - 'rel' => $this->getRel(), - 'rev' => $this->getRev(), - 'order' => $this->getOrder(), - 'resource' => $this->getResource(), - 'privilege' => $this->getPrivilege(), - 'active' => $this->isActive(), - 'visible' => $this->isVisible(), - 'type' => get_class($this), - 'pages' => parent::toArray() - )); + 'label' => $this->getlabel(), + 'fragment' => $this->getFragment(), + 'id' => $this->getId(), + 'class' => $this->getClass(), + 'title' => $this->getTitle(), + 'target' => $this->getTarget(), + 'accesskey' => $this->getAccesskey(), + 'rel' => $this->getRel(), + 'rev' => $this->getRev(), + 'customHtmlAttribs' => $this->getCustomHtmlAttribs(), + 'order' => $this->getOrder(), + 'resource' => $this->getResource(), + 'privilege' => $this->getPrivilege(), + 'active' => $this->isActive(), + 'visible' => $this->isVisible(), + 'type' => get_class($this), + 'pages' => parent::toArray() + ) + ); } // Internal methods: