Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Navigation_PageTypeHandler Class Reference

Defines a page type handler which provides management details for a particular zend navigation container type. More...

Inheritance diagram for P4Cms_Navigation_PageTypeHandler:
P4Cms_Model P4Cms_ModelInterface

List of all members.

Public Member Functions

 getFormCallback ()
 Retrieve the form callback for this type.
 getLabel ()
 Get the human-friendly label for this page type handler.
 isValid ()
 Verifies the current model has a valid className (id).
 prepareForm (P4Cms_Form $form)
 Give form callback an oportunity to modify the passed form.
 setFormCallback ($callback)
 Set a form callback for this type.
 setLabel ($label)
 Set the human-friendly label for this page type handler.

Static Public Member Functions

static fetch ($class)
 Get an instance of the appropriate page handler for the specified class.
static fetchAll ()
 Get all of the valid page type handlers that are available across all modules.

Static Protected Attributes

static $_fields
static $_idField = 'id'

Detailed Description

Defines a page type handler which provides management details for a particular zend navigation container type.

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

static P4Cms_Navigation_PageTypeHandler::fetch ( class) [static]

Get an instance of the appropriate page handler for the specified class.

Parameters:
string | object$classthe page class to get a handler for.
Returns:
P4Cms_Navigation_PageTypeHandler the page handler.
    {
        // normalize input to a string
        if (!is_string($class)) {
            $class = get_class($class);
        }

        // look for the corresponding handler.
        $handlers = static::fetchAll();
        if (isset($handlers[$class])) {
            return $handlers[$class];
        }

        // no matching handler, return a generic handler.
        return new static(array('id' => $class));
    }
static P4Cms_Navigation_PageTypeHandler::fetchAll ( ) [static]

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

Returns:
P4Cms_Model_Iterator all page type handlers in the system.

p4cms.navigation.pageTypeHandlers Return a P4Cms_Navigation_PageTypeHandler (or array of Page Type Handlers) to be included in the page type handler fetchAll results. The last subscriber to return a valid entry for a given ID wins. Page type handlers can provide custom page types for use in navigation hierarchies.

    {
        $handlers = new P4Cms_Model_Iterator;
        $feedback = P4Cms_PubSub::publish('p4cms.navigation.pageTypeHandlers');
        foreach ($feedback as $providedHandlers) {
            // normalize result to always be an array
            if (!is_array($providedHandlers)) {
                $providedHandlers = array($providedHandlers);
            }

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

        return $handlers;
    }
P4Cms_Navigation_PageTypeHandler::getFormCallback ( )

Retrieve the form callback for this type.

See setFormCallback for more details.

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

Get the human-friendly label for this page type handler.

If no explicit label has been set the last component of the class name will be used.

Returns:
string the label for this page handler class
    {
        return $this->_getValue('label')
               ?: ltrim(strrchr($this->getId(), '_'), '_');
    }
P4Cms_Navigation_PageTypeHandler::isValid ( )

Verifies the current model has a valid className (id).

Returns:
bool True - model is valid / False - model is not valid
    {
        return strlen($this->getId())
               && is_subclass_of($this->getId(), 'Zend_Navigation_Container');
    }
P4Cms_Navigation_PageTypeHandler::prepareForm ( P4Cms_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 default form to be modified
Returns:
P4Cms_Form The form to use for this type
    {
        $callback = $this->getFormCallback();
        if (is_callable($callback)) {
            return $callback($form);
        }

        return $form;
    }
P4Cms_Navigation_PageTypeHandler::setFormCallback ( callback)

Set a form callback for this type.

The form callback will be executed by prepareForm to offer type an opportunity to modify the default form.

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_PageTypeHandler 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_PageTypeHandler::setLabel ( label)

Set the human-friendly label for this page type handler.

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

Member Data Documentation

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

Reimplemented from P4Cms_Model.

P4Cms_Navigation_PageTypeHandler::$_idField = 'id' [static, protected]

Reimplemented from P4Cms_Model.


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