Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Form_Element_NestedCheckbox Class Reference

Extends Zend_Form_Element_MultiCheckbox to support nesting items in UL's. More...

Inheritance diagram for P4Cms_Form_Element_NestedCheckbox:
Content_Form_Element_TypeGroup

List of all members.

Public Member Functions

 isValid ($value, $context=null)
 Extends parent to ensure the 'InArray' validator gets a recursively flattened list of valid inputs.

Public Attributes

 $helper = 'formNestedCheckbox'

Detailed Description

Extends Zend_Form_Element_MultiCheckbox to support nesting items in UL's.

This class simply sets the view helper which does all the actual work.

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_Form_Element_NestedCheckbox::isValid ( value,
context = null 
)

Extends parent to ensure the 'InArray' validator gets a recursively flattened list of valid inputs.

Parameters:
string$valuename of checkbox to validate
mixed$contextoptional context
Returns:
bool
    {
        if ($this->registerInArrayValidator()) {
            if (!$this->getValidator('InArray')) {
                $options = array();

                // create a recursive function we will use to flatten
                // the multi-dimensional array of options
                $flatten = function($array, &$flat) use (&$flatten)
                {
                    foreach ($array as $optValue => $optLabel) {
                        if (is_array($optLabel)) {
                            $flatten($optLabel, $flat);
                            continue;
                        }

                        $flat[] = $optValue;
                    }
                };

                // populate options with the flattened version of multi-option values
                $flatten($this->getMultiOptions(), $options);

                $this->addValidator(
                    'InArray',
                    true,
                    array($options)
                );
            }
        }
        return parent::isValid($value, $context);
    }

Member Data Documentation

P4Cms_Form_Element_NestedCheckbox::$helper = 'formNestedCheckbox'

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