Ejemplo n.º 1
0
 /**
  * DOCUMENT ME
  */
 public function configure()
 {
     // This call was missing, preventing easy extension of all media item edit forms at the project level
     parent::configure();
     unset($this['id']);
     unset($this['type']);
     unset($this['service_url']);
     unset($this['slug']);
     unset($this['width']);
     unset($this['height']);
     unset($this['format']);
     if ($this->getObject()) {
         $id = $this->getObject()->getId();
     } else {
         $id = false;
     }
     $this->setWidget('file', new aWidgetFormInputFilePersistent(array()));
     $this->setValidator('file', new aValidatorFilePersistent(array("mime_types" => array("application/pdf", "application/x-pdf"), "required" => !$this->getObject()->getId()), array("mime_types" => "PDF only.", "required" => "Select a PDF file")));
     // These have to be brief to work with Rick's styles
     $this->setValidator('title', new sfValidatorString(array("min_length" => 3, "max_length" => 200, "required" => true), array("min_length" => "Title must be at least 3 characters.", "max_length" => "Title must be <200 characters.", "required" => "You must provide a title.")));
     $this->setWidget('view_is_secure', new sfWidgetFormChoice(array('expanded' => true, 'choices' => array(0 => "Public", 1 => "Hidden"), 'default' => 0)));
     $this->setValidator('view_is_secure', new sfValidatorBoolean());
     $this->widgetSchema->setLabel("view_is_secure", "Permissions");
     $this->widgetSchema->setNameFormat('a_media_item[%s]');
     $this->widgetSchema->setFormFormatterName('aAdmin');
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe');
 }
Ejemplo n.º 2
0
 /**
  * DOCUMENT ME
  */
 public function configure()
 {
     // This call was missing, preventing easy extension of all media item edit forms at the project level
     parent::configure();
     unset($this['id'], $this['type'], $this['slug'], $this['width'], $this['height'], $this['format'], $this['service_url']);
     // Slideshare has very long default embed codes. We're not going to alter our database for them, but we do have to
     // let it be initially pasted so we can get past form validation and regenerate a shorter embed code
     $this->getValidator('embed')->setOption('max_length', 2000);
     $object = $this->getObject();
     $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('required' => true, 'callback' => array($this, 'validateEmbed')), array('required' => "Not a valid embed code", 'invalid' => "Not a valid embed code")));
     $this->setWidget('file', new aWidgetFormInputFilePersistent());
     $item = $this->getObject();
     if (!$item->isNew()) {
         $this->getWidget('file')->setOption('default-preview', $item->getOriginalPath());
     }
     $this->setValidator('file', new aValidatorFilePersistent(array('mime_types' => array('image/jpeg', 'image/png', 'image/gif'), 'required' => false), array('mime_types' => 'JPEG, PNG and GIF only.', 'required' => 'Select a JPEG, PNG or GIF file as a thumbnail')));
     $label = 'Replace Thumbnail';
     if (!$this['file']->getWidget()->getOption('default-preview')) {
         $label = 'Choose Thumbnail';
     }
     $this->widgetSchema->setLabel('file', $label);
     $this->widgetSchema->setLabel('embed', 'Embed Code or URL');
     $this->widgetSchema->setFormFormatterName('aAdmin');
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe');
 }
Ejemplo n.º 3
0
 /**
  * DOCUMENT ME
  */
 public function configure()
 {
     // This call was missing, preventing easy extension of all media item edit forms at the project level
     parent::configure();
     unset($this['id']);
     unset($this['type']);
     unset($this['service_url']);
     unset($this['slug']);
     unset($this['width']);
     unset($this['height']);
     unset($this['format']);
     unset($this['embed']);
     $this->setWidget('file', new aWidgetFormInputFilePersistent(array()));
     $item = $this->getObject();
     // A safe assumption because we always go through the separate upload form on the first pass.
     // This label is a hint that changing the file is not mandatory
     // The 'Replace File' label is safer than superimposing a file button
     // on something that may or may not be a preview or generally a good thing
     // to try to read a button on top of
     $this->getWidget('file')->setLabel('Select a new file');
     if (!$item->isNew()) {
         $this->getWidget('file')->setOption('default-preview', $item->getOriginalPath());
     }
     $mimeTypes = aMediaTools::getOption('mime_types');
     // It comes back as a mapping of extensions to types, get the types
     $extensions = array_keys($mimeTypes);
     $mimeTypes = array_values($mimeTypes);
     $type = false;
     if (!$this->getObject()->isNew()) {
         // You can't change the major type of an existing media object as
         // this would break slots (a .doc where a .gif should be...)
         $type = $this->getObject()->type;
     }
     // What we are selecting to add to a page
     if (!$type) {
         $type = aMediaTools::getType();
     }
     if (!$type) {
         // What we are filtering for
         $type = aMediaTools::getSearchParameter('type');
     }
     if ($type) {
         // This supports composite types like _downloadable
         $infos = aMediaTools::getTypeInfos($type);
         $extensions = array();
         foreach ($infos as $info) {
             if ($info['embeddable']) {
                 // This widget is actually supplying a thumbnail - allow gif, jpg and png
                 $info['extensions'] = array('gif', 'jpg', 'png');
             }
             foreach ($info['extensions'] as $extension) {
                 $extensions[] = $extension;
             }
         }
         $mimeTypes = array();
         $mimeTypesByExtension = aMediaTools::getOption('mime_types');
         foreach ($extensions as $extension) {
             // Careful, if we are filtering for a particular type then not everything
             // will be on the list
             if (isset($mimeTypesByExtension[$extension])) {
                 $mimeTypes[] = $mimeTypesByExtension[$extension];
             }
         }
     }
     // The file is mandatory if it's new. Otherwise
     // we have a problem when they get the file type wrong
     // for one of two and we have to reject that one,
     // then they resubmit - we can add an affirmative way
     // to remove one item from the annotation form later
     $this->setValidator("file", new aValidatorFilePersistent(array("mime_types" => $mimeTypes, 'validated_file_class' => 'aValidatedFile', "required" => $this->getObject()->isNew() ? true : false), array("mime_types" => "The following file types are accepted: " . implode(', ', $extensions))));
     // Necessary to work around FCK's "id and name cannot differ" problem
     // ... But we do it in the action which knows when that matters
     // $this->widgetSchema->setNameFormat('a_media_item_'.$this->getObject()->getId().'_%s');
     // $this->widgetSchema->setFormFormatterName('aAdmin');
 }