protected function renderMarkup(FileUpload $element) { $this->setupAssets(); $file = $element->getFileEntity(); $preview = ''; $translator = $this->getTranslator(); $textDomain = $this->getTranslatorTextDomain(); if ($file) { if (0 === strpos($file->getType(), 'image/')) { $basepath = $this->getView()->plugin('basepath'); $preview = '<img src="' . $basepath($file->getUri()) . '" class="img-polaroid" />'; } else { $preview = '<span>' . $file->getName() . '(' . $file->getPrettySize() . ')</span>'; } } $notice = '<div class="iu-empty-notice" style="padding: 10px; color: lightgrey;"> <div style="padding: 0px 20px 5px;"><span class="yk-icon fa-file-image-o fa-5x"></span></div> <small>' . $translator->translate('Click here to add an image or use drag and drop.') . '</small> </div>'; $markup = ' <div class="iu-wrapper" data-errors=""> <div class="iu-dropzone" id="%1$s-dropzone"> <a class="iu-delete-button btn btn-default btn-xs" id="%1$s-delete"> <span class="yk-icon yk-icon-minus"></span> </a> <div class="iu-preview"> %2$s </div> %5$s <div class="iu-progress"> <span class="yk-icon yk-icon-spinner fa-spin"></span> <span class="iu-progress-percent">0</span>%% </div> __input__ </div> <div id="%1$s-errors" class="iu-errors input-error"> <ul class="errors"> <li class="iu-error-size">%3$s</li> <li class="iu-error-type">%4$s</li> </ul> </div> </div>'; /* * @todo add initial error message display. */ //$messages = $element->getMessages(); $markup = sprintf($markup, $element->getAttribute('id'), $preview, $translator->translate('The file is too big', $textDomain), $translator->translate('The file type is not supported', $textDomain), $notice); return $markup; }
/** * Renders the markup for the file upload element. * * @param FileUpload $element * * @return string */ protected function renderMarkup(FileUpload $element) { $file = $element->getFileEntity(); $preview = ''; $translator = $this->getTranslator(); $textDomain = $this->getTranslatorTextDomain(); $template = ' <li class="fu-file fu-working"> <a href="#abort" class="fu-delete-button btn btn-default btn-xs"> <span class="yk-icon yk-icon-minus"></span> </a> <div class="fu-progress"> <span class="yk-icon yk-icon-spinner fa-spin"></span> <span class="fu-progress-text">0</span> % </div> <a class="fu-file-info" href="__file-uri__" target="_blank"> <span class="yk-icon fa-file-o fa-4x"></span> __file-name__ <br> (__file-size__) </a> <div class="fu-errors input-error"> <ul class="errors"> <li class="fu-error-size">' . $translator->translate('The file is too big', $textDomain) . '</li> <li class="fu-error-type">' . $translator->translate('The file type is not supported', $textDomain) . '</li> <li class="fu-error-count">' . sprintf($translator->translate('You may only upload %d files', $textDomain), $element->getAttribute('data-maxfilecount')) . '</li> </ul> </div> </li>'; /* @var $renderer \Zend\View\Renderer\PhpRenderer */ /* @var $basepath \Zend\View\Helper\BasePath */ $renderer = $this->getView(); $basepath = $renderer->plugin('basepath'); $createFileDisplay = function ($file) use($template, $basepath) { /* @var $file \Core\Entity\FileInterface */ $uri = $basepath($file->getUri()); $name = $file->getName(); $size = $file->getPrettySize(); $icon = 0 === strpos($file->getType(), 'image/') ? 'fa-file-image-o' : 'fa-file-o'; return str_replace(array('#abort', '__file-uri__', '__file-name__', '__file-size__', 'fu-working', 'fa-file-o'), array("{$uri}?do=delete", $uri, $name, $size, '', $icon), $template); }; if ($element->isMultiple()) { if (count($file)) { foreach ($file as $f) { $preview .= $createFileDisplay($f); } } $class = 'fu-multiple'; } else { if ($file) { $preview = $createFileDisplay($file); } $class = 'fu-single'; } $notice = '<small>' . $translator->translate('Click here to add files or use drag and drop.') . '</small>'; $nonemptynotice = '<div class="fu-nonempty-notice"' . ('' == trim($preview) ? ' style="display:none;"' : '') . '>' . $notice . '</div>'; $emptynotice = '<div class="fu-empty-notice"' . ('' == trim($preview) ? '' : ' style="display: none;"') . '> <div class="pull-left"> <span class="yk-icon fa-files-o fa-5x"></span> </div>' . $notice . ' </div>'; $markup = ' <div class="fu-dropzone %1$s" id="%2$s-dropzone"> <span class="fu-template" data-template="%4$s"></span> %6$s <ul class="fu-files"> %3$s </ul> %5$s __input__ </div>'; $markup = sprintf($markup, $class, $element->getAttribute('id'), $preview, $renderer->escapeHtmlAttr(trim($template)), $emptynotice, $nonemptynotice); return $markup; }
/** * @param FileUpload $element * @return string * @since 0.27 */ public function getDropZoneClass(FileUpload $element) { return sprintf('fu-dropzone fu-%s%s', $element->isMultiple() ? 'multiple' : 'single', $this->allowClickableDropZone ? '' : ' fu-non-clickable'); }
public function testSetGetViewHelper() { $viewHelper = "test"; $this->target->setViewHelper($viewHelper); $this->assertEquals($this->target->getViewHelper(), $viewHelper); }