/** * Takes a form and configures each image's widget. * * This is one of only 2 methods the user needs to call manually (the other being configureJCropValidators) * Should be called from the form's configure() method * * @param sfForm $form */ public function configureJCropWidgets(sfForm $form, $formOptions = array()) { foreach ($this->_options['images'] as $fieldName) { if (!($imageConfig = $this->getImageConfig($fieldName))) { continue; } $form->setWidget($fieldName, new sfWidgetFormInputFileInputImageJCroppable(array('invoker' => $this->getInvoker(), 'image_field' => $fieldName, 'image_ratio' => isset($imageConfig['ratio']) ? $imageConfig['ratio'] : false, 'with_delete' => true, 'file_src' => $this->getImageSrc($fieldName, 'editable'), 'template' => '%file%<br />%input%<br />%delete% %delete_label%', 'form' => $form))); foreach (array('x1', 'y1', 'x2', 'y2') as $suffix) { $form->setWidget($fieldName . '_' . $suffix, new sfWidgetFormInputHidden()); } } }
/** * Just to make sure every time a form is embedded, the 'remove' widgets * are added. They are needed in the deleting process */ public function embedForm($name, sfForm $form, $decorator = null) { if ($form instanceof sfFormDoctrine) { $form->setWidget('remove', new sfWidgetFormInputHidden(array(), array('class' => 'remove'))); $form->setValidator('remove', new sfValidatorPass()); } parent::embedForm($name, $form, $decorator); }
public static function replaceWidgets(sfForm $form) { foreach ($form->getWidgetSchema()->getFields() as $name => $widget) { if ($widget instanceof sfWidgetFormDate) { $form->setWidget($name, self::getDateWidget()); } elseif ($widget instanceof sfWidgetFormFilterDate) { $form->getWidget($name)->setOption("from_date", self::getDateWidget(array("use_own_help" => false))); $form->getWidget($name)->setOption("to_date", self::getDateWidget(array("use_own_help" => false))); $form->getWidget($name)->setOption("template", __("from %from_date% to %to_date%")); } elseif ($widget instanceof sfWidgetFormTextarea) { $form->getWidget($name)->setAttribute("rows", 15); $form->getWidget($name)->setAttribute("cols", 100); } if ($name == "attachment") { $form->setWidget($name, new sfWidgetFormInputFile()); } elseif ($name == "created_by" || $name == "updated_by") { if ($form instanceof sfFormPropel) { $form->setWidget($name, new sfWidgetFormInputHidden()); } } elseif ($name == "password") { $form->setWidget($name, new sfWidgetFormInputPassword()); } } }
/** * Add a validated image upload field to a form. * * @param sfForm $form Form to modify * @param string $field_name Name of the image upload field, default 'image' */ public static function addImageField($form, $field_name = 'image') { $form->setWidget($field_name, new sfWidgetFormInputFile()); $form->setValidator($field_name, new sfValidatorImageFile(self::getValidatorOptions(), self::getValidatorMessages())); }
</div> <?php } ?> </div> <?php if ($name == 'polyline') { ?> <!-- TODO The first two lines should be in action. --> <div class="add-stop-wrapper"> <?php $oneFieldForm = new sfForm(); ?> <?php $oneFieldForm->setWidget('nj_stop_id', new sfWidgetFormDoctrineChoice(array('model' => 'NjStop', 'add_empty' => false))); ?> <?php $oneFieldForm->setWidget('nj_stop_lat_lng', new sfWidgetFormDoctrineChoice(array('model' => 'NjStop', 'method' => 'getLatitudeLongitude', 'add_empty' => false))); ?> <?php echo $oneFieldForm['nj_stop_id']->render(); ?> <div class="nj_stop_lat_lng_wrapper" style="display:none;"> <?php echo $oneFieldForm['nj_stop_lat_lng']->render(); ?> </div> <a href="#add-stop" title="Add Stop" class="btn-add-stop">Add Stop</a> </div> <div class="map_wrapper">
/** * Change theme widget to be dropdown of themes * * @param sfForm $form * @return void */ public static function changeThemeWidget(sfForm $form) { $array = self::getThemeWidgetAndValidator(); $form->setWidget('theme', $array['widget']); $form->setValidator('theme', $array['validator']); }