public function setup() { parent::setup(); unset($this->widgetSchema['type']); unset($this->widgetSchema['lft']); unset($this->widgetSchema['rgt']); unset($this->widgetSchema['level']); unset($this->validatorSchema['type']); unset($this->validatorSchema['lft']); unset($this->validatorSchema['rgt']); unset($this->validatorSchema['level']); $this->validatorSchema['tags'] = new sfValidatorAnd(array(new sfValidatorString(), new sfValidatorRegex(array('pattern' => '#^[^, ;]([^, ;]+[,; ] ?)*?[^, ;]+$#'))), array('required' => false)); $directory_choices = sfFilebaseDirectoryTable::getChoices(); $this->widgetSchema['directory'] = new sfWidgetFormTree(array('value_key' => 'id', 'choices' => $directory_choices, 'label_key' => 'filename')); $this->validatorSchema['directory'] = new sfValidatorTree(array('value_key' => 'id', 'label_key' => 'filename', 'choices' => $directory_choices)); if ($this->isNew()) { unset($this->widgetSchema['filename']); unset($this->validatorSchema['filename']); $this->widgetSchema['hash'] = new sfWidgetFormInputSWFUpload(array('require_yui' => true, 'custom_javascripts' => array(public_path('/sfFilebasePlugin/js/fileupload.js')))); $this->validatorSchema['hash'] = new sfFilebasePluginValidatorFile(array('path' => sfFilebasePlugin::getInstance()->getPathname(), 'allow_overwrite' => true, 'required' => true)); $this->widgetSchema['directory']->setDefault($directory_choices[0]['id']); } else { unset($this->widgetSchema['hash']); unset($this->validatorSchema['hash']); $this->validatorSchema['filename'] = new sfValidatorString(); $p = $this->getObject()->getNode()->getParent(); $parent_id = $p instanceof sfFilebaseDirectory ? $p->getId() : 0; $this->widgetSchema['directory']->setDefault($parent_id); } $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'checkUpload')))); }
public function setup() { parent::setup(); unset($this->widgetSchema['hash']); unset($this->widgetSchema['type']); unset($this->widgetSchema['lft']); unset($this->widgetSchema['rgt']); unset($this->widgetSchema['level']); unset($this->validatorSchema['hash']); unset($this->validatorSchema['type']); unset($this->validatorSchema['lft']); unset($this->validatorSchema['rgt']); unset($this->validatorSchema['level']); $this->validatorSchema['tags'] = new sfValidatorAnd(array(new sfValidatorString(), new sfValidatorRegex(array('pattern' => '#^[^, ;]([^, ;]+[,; ] ?)*?[^, ;]+$#'))), array('required' => false)); $this->validatorSchema['filename'] = new sfValidatorAnd(array(new sfValidatorString(), new sfValidatorRegex(array('pattern' => '#^[\\w\\-\\.]+$#'))), array('required' => true)); $restrict_select_below = $this->isNew() ? false : $this->getObject()->getId(); $directory_choices = sfFilebaseDirectoryTable::getChoices(); $this->widgetSchema['directory'] = new sfWidgetFormTree(array('value_key' => 'id', 'label_key' => 'filename', 'choices' => $directory_choices)); $this->validatorSchema['directory'] = new sfValidatorTree(array('value_key' => 'id', 'label_key' => 'filename', 'choices' => $directory_choices, 'restrict_select_below' => $restrict_select_below)); if (!$this->isNew()) { $p = $this->getObject()->getNode()->getParent(); if ($p) { $this->widgetSchema['directory']->setDefault($this->getObject()->getNode()->getParent()->getId()); } } $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'checkUpload')))); }