protected function configure($options = array(), $attributes = array()) { parent::configure($options, $attributes); $this->setOption('file_src', '/images/store'); $this->setOption('is_image', true); $this->setOption('with_delete', false); $this->setOption('template', '<div>%file%<br />%input%<br />%delete% %delete_label%</div>'); }
public function render($name, $value = null, $attributes = array(), $errors = array()) { if ($file = $this->getFileInfo()) { $this->setOption('file_src', $file->web_path); $this->setOption('edit_mode', true); } return parent::render($name, $value, $attributes, $errors); }
} $t = new lime_test(7); // ->render() $t->diag('->render()'); try { new sfWidgetFormInputFileEditable(); $t->fail('->render() throws an exception if you don\' pass a "file_src" option.'); } catch (RuntimeException $e) { $t->pass('->render() throws an exception if you don\' pass a "file_src" option.'); } $w = new sfWidgetFormInputFileEditable(array('file_src' => '-foo-')); $t->is($w->render('foo'), '-foo-<br /><input type="file" name="foo" id="foo" /><br /><input type="checkbox" name="foo_delete" id="foo_delete" /> <label for="foo_delete">remove the current file</label>', '->render() renders the widget as HTML'); $t->diag('with_delete option'); $w = new sfWidgetFormInputFileEditable(array('file_src' => '-foo-', 'with_delete' => false)); $t->is($w->render('foo'), '-foo-<br /><input type="file" name="foo" id="foo" /><br /> ', '->render() renders the widget as HTML'); $t->diag('delete_label option'); $w = new sfWidgetFormInputFileEditable(array('file_src' => '-foo-', 'delete_label' => 'delete')); $t->is($w->render('foo'), '-foo-<br /><input type="file" name="foo" id="foo" /><br /><input type="checkbox" name="foo_delete" id="foo_delete" /> <label for="foo_delete">delete</label>', '->render() renders the widget as HTML'); $t->diag('delete label translation'); $ws = new sfWidgetFormSchema(); $ws->addFormFormatter('stub', new FormFormatterStub()); $ws->setFormFormatterName('stub'); $w = new sfWidgetFormInputFileEditable(array('file_src' => '-foo-')); $w->setParent($ws); $t->is($w->render('foo'), '-foo-<br /><input type="file" name="foo" id="foo" /><br /><input type="checkbox" name="foo_delete" id="foo_delete" /> <label for="foo_delete">translation[remove the current file]</label>', '->render() renders the widget as HTML'); $t->diag('is_image option'); $w = new sfWidgetFormInputFileEditable(array('file_src' => '-foo-', 'is_image' => true)); $t->is($w->render('foo'), '<img src="-foo-" /><br /><input type="file" name="foo" id="foo" /><br /><input type="checkbox" name="foo_delete" id="foo_delete" /> <label for="foo_delete">remove the current file</label>', '->render() renders the widget as HTML'); $t->diag('template option'); $w = new sfWidgetFormInputFileEditable(array('file_src' => '-foo-', 'template' => '%input%')); $t->is($w->render('foo'), '<input type="file" name="foo" id="foo" />', '->render() renders the widget as HTML');
public function __construct($options = array(), $attributes = array()) { $this->addOption('sizes'); $this->addOption('labels'); parent::__construct($options, $attributes); }