7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
17 * @subpackage Decorator
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
22 /** Zend_Form_Decorator_Abstract */
23 require_once 'Zend/Form/Decorator/Abstract.php';
25 /** Zend_Form_Decorator_Marker_File_Interface */
26 require_once 'Zend/Form/Decorator/Marker/File/Interface.php';
28 /** Zend_File_Transfer_Adapter_Http */
29 require_once 'Zend/File/Transfer/Adapter/Http.php';
32 * Zend_Form_Decorator_File
34 * Fixes the rendering for all subform and multi file elements
38 * @subpackage Decorator
39 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
40 * @license http://framework.zend.com/license/new-bsd New BSD License
41 * @version $Id: File.php 16971 2009-07-22 18:05:45Z mikaelkael $
43 class Zend_Form_Decorator_File
44 extends Zend_Form_Decorator_Abstract
45 implements Zend_Form_Decorator_Marker_File_Interface
48 * Attributes that should not be passed to helper
51 protected $_attribBlacklist = array('helper', 'placement', 'separator', 'value');
54 * Default placement: append
57 protected $_placement = 'APPEND';
60 * Get attributes to pass to file helper
64 public function getAttribs()
66 $attribs = $this->getOptions();
68 if (null !== ($element = $this->getElement())) {
69 $attribs = array_merge($attribs, $element->getAttribs());
72 foreach ($this->_attribBlacklist
as $key) {
73 if (array_key_exists($key, $attribs)) {
74 unset($attribs[$key]);
84 * @param string $content
87 public function render($content)
89 $element = $this->getElement();
90 if (!$element instanceof Zend_Form_Element
) {
94 $view = $element->getView();
95 if (!$view instanceof Zend_View_Interface
) {
99 $name = $element->getName();
100 $attribs = $this->getAttribs();
101 if (!array_key_exists('id', $attribs)) {
102 $attribs['id'] = $name;
105 $separator = $this->getSeparator();
106 $placement = $this->getPlacement();
108 $size = $element->getMaxFileSize();
110 $element->setMaxFileSize(0);
111 $markup[] = $view->formHidden('MAX_FILE_SIZE', $size);
114 if (Zend_File_Transfer_Adapter_Http
::isApcAvailable()) {
115 $markup[] = $view->formHidden('APC_UPLOAD_PROGRESS', uniqid(), array('id' => 'progress_key'));
116 } else if (Zend_File_Transfer_Adapter_Http
::isUploadProgressAvailable()) {
117 $markup[] = $view->formHidden('UPLOAD_IDENTIFIER', uniqid(), array('id' => 'progress_key'));
120 if ($element->isArray()) {
122 $count = $element->getMultiFile();
123 for ($i = 0; $i < $count; ++
$i) {
124 $htmlAttribs = $attribs;
125 $htmlAttribs['id'] .= '-' . $i;
126 $markup[] = $view->formFile($name, $htmlAttribs);
129 $markup[] = $view->formFile($name, $attribs);
132 $markup = implode($separator, $markup);
134 switch ($placement) {
136 return $markup . $separator . $content;
139 return $content . $separator . $markup;