Perforce Chronicle 2012.2/486814
API Documentation
|
Defines a dynamic handler which operates on dynamic menu items. More...
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 |
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.
P4Cms_Navigation_DynamicHandler::callExpansionCallback | ( | $ | item, |
$ | options | ||
) |
Call the expansion callback for this dynamic handler.
P4Cms_Navigation_Page_Dynamic | $item | the dynamic item to be expanded. |
array | $options | options (hints) to influence expansion. |
{ $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.
string | $id | The id to check for |
{ $handlers = static::fetchAll(); return isset($handlers[$id]); }
static P4Cms_Navigation_DynamicHandler::fetch | ( | $ | id | ) | [static] |
Get an instance of the specified dynamic handler.
string | $id | the id of the handler to get an instance of. |
{ $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.
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.
P4Cms_Navigation_Exception | If 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.
{ return $this->_getValue('formCallback'); }
P4Cms_Navigation_DynamicHandler::getLabel | ( | ) |
Get the human-friendly label for this dynamic handler.
{ return $this->_getValue('label'); }
P4Cms_Navigation_DynamicHandler::hasExpansionCallback | ( | ) |
Check if this handler has a valid expansion callback.
{ return is_callable($this->_getValue('expansionCallback')); }
P4Cms_Navigation_DynamicHandler::isValid | ( | ) |
Verifies the current model has a callback and label.
{ 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.
P4Cms_Form | $form | the menu item form to be modified |
{ $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.
string | $callback | the callback for this handler. |
P4Cms_Navigation_Exception | if 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.
null | callable | $callback | the callback to set or null. |
{ 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.
string | $label | the display label for this handler. |
{ $this->_setValue('label', $label); return $this; }
P4Cms_Navigation_DynamicHandler::$_fields [static, protected] |
array( 'label' => array( 'accessor' => 'getLabel', 'mutator' => 'setLabel' ), 'expansionCallback' => array( 'accessor' => 'getExpansionCallback', 'mutator' => 'setExpansionCallback' ), 'formCallback' => array( 'accessor' => 'getFormCallback', 'mutator' => 'setFormCallback' ) )
Reimplemented from P4Cms_Model.