/** * Configures the current widget. * * Available options: * * * from_label: The label for the from date widget * * to_label: The label for the to date widget * * * from_label_template: The template used to render label for from date widget * Available placeholders: %from_id%, %from_label% * * to_label_template: The template used to render label for to date widget * Available placeholders: %to_id%, %to_label% * * * template: The template to use to render the widget * Available placeholders: %from_date%, %to_date% %from_label% %to_label% * * also see options in sfWidgetFormDateRange * * @param array $options An array of options * @param array $attributes An array of default HTML attributes * * @see ohrmWidgetFormDateRange */ protected function configure($options = array(), $attributes = array()) { parent::configure($options, $attributes); $this->addOption('from_label', ''); $this->addOption('to_label', 'to'); $this->addOption('from_label_template', "<label for='%from_id%' class='date_range_label'>%from_label%</label>"); $this->addOption('to_label_template', "<label> </label><label for='%to_id%' class='date_range_label'>%to_label%</label>"); $this->addOption('use_separate_containers', true); $this->addOption('container_separator', '</li><li>'); $this->addOption('template', '%from_label% %from_date% %container_separator%%to_label% %to_date%'); }
{ public $translateSubjects = array(); public function __construct() { } public function translate($subject, $parameters = array()) { $this->translateSubjects[] = $subject; return sprintf('translation[%s]', $subject); } } class WidgetFormStub extends sfWidget { public function __construct() { } public function render($name, $value = null, $attributes = array(), $errors = array()) { return sprintf('##%s##', __CLASS__); } } $t = new lime_test(2); // ->render() $t->diag('->render()'); $ws = new sfWidgetFormSchema(); $ws->addFormFormatter('stub', $formatter = new FormFormatterMock()); $ws->setFormFormatterName('stub'); $w = new sfWidgetFormDateRange(array('from_date' => new WidgetFormStub(), 'to_date' => new WidgetFormStub())); $w->setParent($ws); $t->is($w->render('foo'), 'translation[from ##WidgetFormStub## to ##WidgetFormStub##]', '->render() remplaces %from_date% and %to_date%'); $t->is($formatter->translateSubjects, array('from %from_date% to %to_date%'), '->render() translates the template option');
/** * @param string $name The element name * @param string $value The date displayed in this widget * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes * @param array $errors An array of errors for the field * * @return string An HTML tag string * * @see sfWidgetForm */ public function render($name, $value = null, $attributes = array(), $errors = array()) { $values = array_merge(array('is_empty' => ''), is_array($value) ? $value : array()); return strtr($this->getOption('filter_template'), array('%date_range%' => parent::render($name, $value, $attributes, $errors), '%empty_checkbox%' => $this->getOption('with_empty') ? $this->renderTag('input', array('type' => 'checkbox', 'name' => $name . '[is_empty]', 'checked' => $values['is_empty'] ? 'checked' : '')) : '', '%empty_label%' => $this->getOption('with_empty') ? $this->renderContentTag('label', $this->getOption('empty_label'), array('for' => $this->generateId($name . '[is_empty]'))) : '')); }