Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Navigation_DynamicHandler Class Reference

Defines a dynamic handler which operates on dynamic menu items. More...

Inheritance diagram for P4Cms_Navigation_DynamicHandler:
P4Cms_Model P4Cms_ModelInterface

List of all members.

Public Member Functions

 callExpansionCallback ($item, $options)
 Call the expansion callback for this dynamic handler.
 getExpansionCallback ()
 Get the expansion callback for this dynamic handler.
 getFormCallback ()
 Retrieve the form callback for this dynamic page type.
 getLabel ()
 Get the human-friendly label for this dynamic handler.
 hasExpansionCallback ()
 Check if this handler has a valid expansion callback.
 isValid ()
 Verifies the current model has a callback and label.
 prepareForm (Zend_Form $form)
 Give form callback an oportunity to modify the passed form.
 setExpansionCallback ($callback)
 Set the expansion callback for this dynamic handler.
 setFormCallback ($callback)
 Set a form callback for this dynamic page type.
 setLabel ($label)
 Set the human-friendly label for this dynamic handler.

Static Public Member Functions

static exists ($id)
 Checks if the specified handler id exists or not.
static fetch ($id)
 Get an instance of the specified dynamic handler.
static fetchAll ()
 Get all of the valid dynamic handlers that are available across all modules.

Static Protected Attributes

static $_fields

Detailed Description

Defines a dynamic handler which operates on dynamic menu items.

It provides an expansion callback which will replace a dynamic menu item with zero or more navigation pages/containers.

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

P4Cms_Navigation_DynamicHandler::callExpansionCallback ( item,
options 
)

Call the expansion callback for this dynamic handler.

Parameters:
P4Cms_Navigation_Page_Dynamic$itemthe dynamic item to be expanded.
array$optionsoptions (hints) to influence expansion.
Returns:
array|Zend_Navigation_Container|null the replacement menu items.
See also:
setExpansionCallback for function signature details.
    {
        $callback = $this->getExpansionCallback();
        return call_user_func($callback, $item, $options);
    }
static P4Cms_Navigation_DynamicHandler::exists ( id) [static]

Checks if the specified handler id exists or not.

Parameters:
string$idThe id to check for
Returns:
bool true if exists false otherwise
    {
        $handlers = static::fetchAll();

        return isset($handlers[$id]);
    }
static P4Cms_Navigation_DynamicHandler::fetch ( id) [static]

Get an instance of the specified dynamic handler.

Parameters:
string$idthe id of the handler to get an instance of.
Returns:
P4Cms_Navigation_DynamicHandler the requested dynamic handler.
    {
        $handlers = static::fetchAll();

        if (!isset($handlers[$id])) {
            // unable to find the requested handler.
            throw new P4Cms_Model_NotFoundException(
                "Cannot fetch handler. The requested handler does not exist."
            );
        }

        return $handlers[$id];
    }
static P4Cms_Navigation_DynamicHandler::fetchAll ( ) [static]

Get all of the valid dynamic handlers that are available across all modules.

Returns:
P4Cms_Model_Iterator all dynamic handlers in the system.

p4cms.navigation.dynamicHandlers Return a P4Cms_Navigation_DynamicHandler (or array of Dynamic Handlers) to be included in the dynamic handler fetchAll results. The last subscriber to return a valid entry for a given ID wins. Dynamic menu handlers can provide dynamically-generated navigation entries.

    {
        $handlers = new P4Cms_Model_Iterator;
        $feedback = P4Cms_PubSub::publish('p4cms.navigation.dynamicHandlers');
        foreach ($feedback as $providedHandlers) {
            if (!is_array($feedback)) {
                $feedback = array($feedback);
            }

            foreach ($providedHandlers as $handler) {
                if ($handler instanceof P4Cms_Navigation_DynamicHandler
                    && $handler->isValid()) {
                    $handlers[$handler->getId()] = $handler;
                }
            }
        }

        return $handlers;
    }
P4Cms_Navigation_DynamicHandler::getExpansionCallback ( )

Get the expansion callback for this dynamic handler.

Returns:
callback The callback function to provide replacement items
Exceptions:
P4Cms_Navigation_ExceptionIf no expansion callback has been set
    {
        $callback = $this->_getValue('expansionCallback');

        if (!is_callable($callback)) {
            throw new P4Cms_Navigation_Exception(
                'Cannot get expansion callback, no valid callback has been set'
            );
        }

        return $callback;
    }
P4Cms_Navigation_DynamicHandler::getFormCallback ( )

Retrieve the form callback for this dynamic page type.

See setFormCallback for more details.

Returns:
null|callable the callback or null
    {
        return $this->_getValue('formCallback');
    }
P4Cms_Navigation_DynamicHandler::getLabel ( )

Get the human-friendly label for this dynamic handler.

Returns:
string the display label for this handler.
    {
        return $this->_getValue('label');
    }
P4Cms_Navigation_DynamicHandler::hasExpansionCallback ( )

Check if this handler has a valid expansion callback.

Returns:
bool true if the handler has a valid callback, false otherwise
    {
        return is_callable($this->_getValue('expansionCallback'));
    }
P4Cms_Navigation_DynamicHandler::isValid ( )

Verifies the current model has a callback and label.

Returns:
bool True - model is valid / False - model is not valid
    {
        return $this->hasExpansionCallback() && strlen($this->getLabel());
    }
P4Cms_Navigation_DynamicHandler::prepareForm ( Zend_Form $  form)

Give form callback an oportunity to modify the passed form.

If no callback is present the form is returned unmodified.

Parameters:
P4Cms_Form$formthe menu item form to be modified
Returns:
P4Cms_Form the form to use for this dynamic item type.
    {
        $callback = $this->getFormCallback();
        if (is_callable($callback)) {
            return $callback($form);
        }

        return $form;
    }
P4Cms_Navigation_DynamicHandler::setExpansionCallback ( callback)

Set the expansion callback for this dynamic handler.

The expected function signature is:

function($item, $options) { return array|Zend_Navigation_Container|null; }

The options parameter is an array of options (such as max-depth, max-items) that can be used as a hint to reduce the amount of work done to expand the dynamic item. It is not necessary to honor these options as they will be enforced by the P4Cms_Menu class.

If the replacement items have unique identifiers, it is advisable to set the id of each item in the 'expansionId' field. This will allow the system to consistently locate each item (e.g. for the purposes of root selection).

Note that the menu-root option will be set to an expansion id if the menu root is within a expanded dynamic menu item.

Parameters:
string$callbackthe callback for this handler.
Returns:
P4Cms_Navigation_DynamicHandler provides fluent interface.
Exceptions:
P4Cms_Navigation_Exceptionif passed value is not callable
    {
        if (!is_callable($callback)) {
            throw new P4Cms_Navigation_Exception(
                'Cannot set expansion callback, passed value is not callable'
            );
        }

        $this->_setValue('expansionCallback', $callback);

        return $this;
    }
P4Cms_Navigation_DynamicHandler::setFormCallback ( callback)

Set a form callback for this dynamic page type.

The form callback will be executed by prepareForm to offer dynamic handler an opportunity to modify a form for editing dynamic menu items.

The callback should expect a P4Cms_Form for its sole argument and must return a P4Cms_Form.

Parameters:
null | callable$callbackthe callback to set or null.
Returns:
P4Cms_Navigation_DynamicHandler provides fluent interface.
    {
        if ($callback !== null && !is_callable($callback)) {
            throw new InvalidArgumentException('Form callback must be callable or null');
        }

        return $this->_setValue('formCallback', $callback);
    }
P4Cms_Navigation_DynamicHandler::setLabel ( label)

Set the human-friendly label for this dynamic handler.

Parameters:
string$labelthe display label for this handler.
Returns:
P4Cms_Navigation_DynamicHandler provides fluent interface.
    {
        $this->_setValue('label', $label);

        return $this;
    }

Member Data Documentation

P4Cms_Navigation_DynamicHandler::$_fields [static, protected]
Initial value:
 array(
        'label'             => array(
            'accessor'      => 'getLabel',
            'mutator'       => 'setLabel'
        ),
        'expansionCallback' => array(
            'accessor'      => 'getExpansionCallback',
            'mutator'       => 'setExpansionCallback'
        ),
        'formCallback'      => array(
            'accessor'      => 'getFormCallback',
            'mutator'       => 'setFormCallback'
        )
    )

Reimplemented from P4Cms_Model.


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