Perforce Chronicle 2012.2/486814
API Documentation

Content_Form_Decorator_File Class Reference

Extends Zend_Form_Decorator_File to present options on handling an existing file if one is set. More...

List of all members.

Public Member Functions

 render ($content)
 Extend render to show existing file if set.

Protected Attributes

 $_dojoType = "p4cms.content.FileUpload"

Detailed Description

Extends Zend_Form_Decorator_File to present options on handling an existing file if one is set.

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

Content_Form_Decorator_File::render ( content)

Extend render to show existing file if set.

Parameters:
string$contentThe content to render.
Returns:
string
    {
        $content = parent::render($content);

        // if the element has an existing file, present options
        // to keep, remove or replace it.
        $element = $this->getElement();
        if ($element->hasExistingFile()) {
            $info = $element->getExistingFileInfo();

            $html = "<div class='existing-file'>";
            if (isset($info['iconUri'])) {
                $html .= '<span class="existing-file-icon">'
                      .  '<img src="'. $info['iconUri'] .'"></span>';
            }
            if (isset($info['filename'])) {
                $html .= '<span class="existing-file-name">'
                      .  htmlspecialchars($info['filename'])
                      . '</span>';
            }

            // build up action options for existing file.
            $inputName = $element->getName() . '-existing-file-action';
            $options   = array(
                Content_Form_Element_File::ACTION_KEEP    => 'Keep Existing',
                Content_Form_Element_File::ACTION_REMOVE  => 'Remove Existing',
                Content_Form_Element_File::ACTION_REPLACE => 'Replace Existing',
            );

            $html .= '<ul class="existing-file-options">';
            foreach ($options as $value => $label) {
                $actionId = $element->getId() . '-action-' . $value;
                $checked  = $element->getActionFieldValue() === $value ? ' checked="true"' : '';
                $html    .= "<li>";
                $html    .= "<input id=\"$actionId\" name=\"$inputName\"";
                $html    .= " type=\"radio\" value=\"$value\" $checked>";
                $html    .= "<label for=\"$actionId\">$label</label>";
                $html    .= "</li>";
            }
            $html .= '</ul></div>';

            $content = $html . $content;
        }

        // get list of valid extensions from validator.
        $extensions = array();
        $minSize    = 0;
        $maxSize    = 0;
        
        $validators = $element->getValidators();
        foreach ($validators as $validator) {
            if ($validator instanceof Zend_Validate_File_Extension) {
                $extensions = $validator->getExtension();
            }
            if ($validator instanceof Zend_Validate_File_Size) {
                $minSize = $validator->getMin(true);
                $maxSize = $validator->getMax(true);
            }
        }
        
        // wrap file upload controls in a dijit.
        $view    = $element->getView();
        $content = $view->customDijit(
            "dijit-" . $element->getId(),
            $content,
            array(
                "dojoType"      => $this->_dojoType,
                "extensions"    => Zend_Json::encode($extensions),
                "minSize"       => $minSize,
                "maxSize"       => $maxSize,
                "required"      => $element->isRequired()
            )
        );
        
        return $content;
    }

Member Data Documentation

Content_Form_Decorator_File::$_dojoType = "p4cms.content.FileUpload" [protected]

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