Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Form_Decorator_Label Class Reference

Extends Zend_Form_Decorator_Label to exclude labelling of hidden form elements. More...

List of all members.

Public Member Functions

 getClass ()
 Get class with which to define label.
 getLabel ()
 Renders a label and optionally include a link to the appropriate help documentation.
 render ($content)
 Extend render to exclude hidden and hash elements.

Detailed Description

Extends Zend_Form_Decorator_Label to exclude labelling of hidden form elements.

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_Decorator_Label::getClass ( )

Get class with which to define label.

Appends 'disabled' to the class returned from the Zend decorator for disabled elements

Returns:
string
    {
        $class   = parent::getClass();
        $element = $this->getElement();
        if ($element->getAttrib('disabled') || $element->getAttrib('disable')) {
            $class .= " disabled";
        }
        if ($element->getAttrib('readOnly') || $element->getAttrib('readonly')) {
            $class .= " readonly";
        }

        return $class;
    }
P4Cms_Form_Decorator_Label::getLabel ( )

Renders a label and optionally include a link to the appropriate help documentation.

Returns:
string The rendered label.
    {
        $label = parent::getLabel();
        if ($this->getOption('helpUri')) {
            $helpUri = (string) $this->getOption('helpUri');
            $this->removeOption('helpUri');

            $label = $label . $this->getSeparator()
                   . '<a class="helpLink" href="' . $helpUri
                   .'" target="_blank">(?)</a>';
        }
        return $label;
    }
P4Cms_Form_Decorator_Label::render ( content)

Extend render to exclude hidden and hash elements.

Parameters:
string$contentThe content to render.
Returns:
string
    {
        if ($this->getElement() instanceof Zend_Form_Element_Hidden
            || $this->getElement() instanceof Zend_Form_Element_Hash
        ) {
            return $content;
        }

        //if escaping label, store it, escape label, turn it off
        $shouldEscape = $this->getOption('escape');

        if ($this->getOption('helpUri') && $shouldEscape !== false) {
            // disables escaping so we can add html
            // if escaping has not been turned off, escape the label first
            $originalLabel = parent::getLabel();
            $label = $this->getElement()->getView()->escape($originalLabel);

            $this->setOption('escape', false);
            $this->getElement()->setLabel($label);
        }
        $content = parent::render($content);

        //after parent:: render, restore to previous
        if ($this->getOption('helpUri') && $shouldEscape) {
            $this->setOption('escape', true);
            $this->getElement()->setLabel($originalLabel);
        }
        return $content;
    }

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