Perforce Chronicle 2012.2/486814
API Documentation

Menu_View_Helper_Menu Class Reference

Enhanced version of Zend's menu helper. More...

Inheritance diagram for Menu_View_Helper_Menu:
Ui_View_Helper_Toolbar

List of all members.

Public Member Functions

 htmlify ($page)
 Replaces parent htmlify so that we can produce customized markup for page types that require it.
 menu ($container=null, array $options=array())
 This is the menu helper entry point.
 render (Zend_Navigation_Container $container=null)
 Renders menu - extended to pass instance options to renderMenu method.
 renderMenu (Zend_Navigation_Container $container=null, array $options=array())
 Extends the parent helper renderer to capture the options so that they can be re-used by the htmlify method.

Protected Attributes

 $_options = array()

Detailed Description

Enhanced version of Zend's menu helper.

  • Adds support for a 'click' property (onClick attribute) on pages
  • Adds ability to pass menu id and options directly
  • Adds ability to specify before and after label text for menu items
Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Menu_View_Helper_Menu::htmlify ( page)

Replaces parent htmlify so that we can produce customized markup for page types that require it.

Overrides Zend_View_Helper_Navigation_Menu::htmlify().

Parameters:
Zend_Navigation_Page$pagepage to generate HTML for
Returns:
string HTML string for the given page

Reimplemented in Ui_View_Helper_Toolbar.

    {
        // get label and title for translating
        $label = $page->getLabel();
        $title = $page->getTitle();

        // translate label and title?
        if ($this->getUseTranslator() && $t = $this->getTranslator()) {
            if (is_string($label) && !empty($label)) {
                $label = $t->translate($label);
            }
            if (is_string($title) && !empty($title)) {
                $title = $t->translate($title);
            }
        }

        // always provide a type class for styling purposes.
        $typeClass = 'type-' . strtolower(end(explode('_', get_class($page))));

        // get attribs for element
        $attribs = array(
            'id'        => $page->getId(),
            'title'     => $title,
            'class'     => trim($page->getClass() . " " . $typeClass),
            'onclick'   => $page->get("onClick"),
        );

        // does page have a href?
        $beforeLabel = $afterLabel = '';
        if ($href = $page->getHref()) {
            $element = 'a';
            $attribs['href'] = $href;
            $attribs['target'] = $page->getTarget();
            $beforeLabel = array_key_exists('beforeLabel', $this->_options)
                ? $this->_options['beforeLabel']
                : '';
            $afterLabel = array_key_exists('afterLabel', $this->_options)
                ? $this->_options['afterLabel']
                : '';
        } else {
            $element = 'span';
        }

        return '<' . $element . $this->_htmlAttribs($attribs) . '>'
             . $beforeLabel . $this->view->escape($label) . $afterLabel
             . '</' . $element . '>';
    }
Menu_View_Helper_Menu::menu ( container = null,
array $  options = array() 
)

This is the menu helper entry point.

It has been extended to add support for passing a menu object or id (string) as well as options.

If the menu exists, it will be fetched; otherwise, an empty container will be used.

Parameters:
mixed$containeroptional - menu or container to operate on
array$optionsoptions to apply when rendering this menu
Returns:
Menu_View_Helper_Menu fluent interface, returns self
    {
        if ($container && !$container instanceof Zend_Navigation_Container) {
            if (!$container instanceof P4Cms_Menu && P4Cms_Menu::exists($container)) {
                $container = P4Cms_Menu::fetch($container);
            }
            if ($container instanceof P4Cms_Menu) {
                // tag the page cache so it can be appropriately cleared later
                if (P4Cms_Cache::canCache('page')) {
                    P4Cms_Cache::getCache('page')
                        ->addTag('p4cms_menu')
                        ->addTag('p4cms_menu_' . bin2hex($container->getId()));
                }

                $container = $container->getExpandedContainer();
            } else {
                $container = new Zend_Navigation;
            }
        }
        
        if (null !== $container) {
            $this->setContainer($container);
        }

        // keep options around for render time.        
        $this->_options = $options;

        return $this;
    }
Menu_View_Helper_Menu::render ( Zend_Navigation_Container $  container = null)

Renders menu - extended to pass instance options to renderMenu method.

If a partial view is registered in the helper, the menu will be rendered using the given partial script. If no partial is registered, the menu will be rendered as an 'ul' element by the helper's internal method.

Parameters:
Zend_Navigation_Container$container[optional] container to render. Default is to render the container registered in the helper.
Returns:
string helper output
    {
        if ($partial = $this->getPartial()) {
            return $this->renderPartial($container, $partial);
        } else {
            return $this->renderMenu($container, $this->_options);
        }
    }
Menu_View_Helper_Menu::renderMenu ( Zend_Navigation_Container $  container = null,
array $  options = array() 
)

Extends the parent helper renderer to capture the options so that they can be re-used by the htmlify method.

Parameters:
Zend_Navigation_Container$container[optional] container to create menu from. Default is to use the container retrieved from getContainer().
array$options[optional] options for controlling rendering
Returns:
string rendered menu

Reimplemented in Ui_View_Helper_Toolbar.

    {
        $this->_options = $options = $this->_normalizeOptions($options);
        
        return parent::renderMenu($container, $options);
    }

Member Data Documentation

Menu_View_Helper_Menu::$_options = array() [protected]

The documentation for this class was generated from the following file: