Ejemplo n.º 1
0
 /**
  * Add appropriate validators, filters, and hidden elements for  a file
  * upload element.
  *
  * @param Zend_Form_Element_File $element
  */
 private function _processFileElement($element)
 {
     $element->setDestination(Zend_Registry::get('storage')->getTempDir());
     $options = $this->getThemeOptions();
     $fileName = @$options[$element->getName()];
     if ($fileName) {
         $storage = Zend_Registry::get('storage');
         $fileUri = $storage->getUri($storage->getPathByType($fileName, 'theme_uploads'));
     } else {
         $fileUri = null;
     }
     // Add extension/mimetype filtering.
     if (get_option(File::DISABLE_DEFAULT_VALIDATION_OPTION) != '1') {
         $element->addValidator(new Omeka_Validate_File_Extension(self::$allowedExtensions));
         $element->addValidator(new Omeka_Validate_File_MimeType(self::$allowedMimeTypes));
         $element->addValidator(new Zend_Validate_File_Size(array('max' => self::MAX_UPLOAD_SIZE)));
     }
     // Make sure the file was uploaded before adding the Rename filter to the element
     if ($element->isUploaded()) {
         $this->_addFileRenameFilter($element);
     }
     // add a hidden field to store whether already exists
     $hiddenElement = new Zend_Form_Element_Hidden(self::THEME_FILE_HIDDEN_FIELD_NAME_PREFIX . $element->getName());
     $hiddenElement->setValue($fileUri);
     $hiddenElement->setDecorators(array('ViewHelper', 'Errors'));
     $hiddenElement->setIgnore(true);
     $this->addElement($hiddenElement);
 }
Ejemplo n.º 2
0
 public function testIsUploaded()
 {
     $this->element->setTransferAdapter(new Zend_Form_Element_FileTest_MockAdapter());
     $this->assertEquals(true, $this->element->isUploaded());
 }