|
Perforce Chronicle 2012.2/486814
API Documentation
|
Extends Zend_Form_Decorator_File to present options on handling an existing file if one is set. More...
Public Member Functions | |
| render ($content) | |
| Extend render to show existing file if set. | |
Protected Attributes | |
| $_dojoType = "p4cms.content.FileUpload" | |
Extends Zend_Form_Decorator_File to present options on handling an existing file if one is set.
| Content_Form_Decorator_File::render | ( | $ | content | ) |
Extend render to show existing file if set.
| string | $content | The content to render. |
{
$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;
}
Content_Form_Decorator_File::$_dojoType = "p4cms.content.FileUpload" [protected] |