| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfWidgetFormFilterInput extends sfWidgetForm |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Constructor. |
|---|
| 23 |
* |
|---|
| 24 |
* Available options: |
|---|
| 25 |
* |
|---|
| 26 |
* * with_empty: Whether to add the empty checkbox (true by default) |
|---|
| 27 |
* * empty_label: The label to use when using an empty checkbox |
|---|
| 28 |
* * template: The template to use to render the widget |
|---|
| 29 |
* Available placeholders: %input%, %empty_checkbox%, %empty_label% |
|---|
| 30 |
* |
|---|
| 31 |
* @param array $options An array of options |
|---|
| 32 |
* @param array $attributes An array of default HTML attributes |
|---|
| 33 |
* |
|---|
| 34 |
* @see sfWidgetForm |
|---|
| 35 |
*/ |
|---|
| 36 |
protected function configure($options = array(), $attributes = array()) |
|---|
| 37 |
{ |
|---|
| 38 |
$this->addOption('with_empty', true); |
|---|
| 39 |
$this->addOption('empty_label', 'is empty'); |
|---|
| 40 |
$this->addOption('template', '%input%<br />%empty_checkbox% %empty_label%'); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
* @param string $name The element name |
|---|
| 45 |
* @param string $value The value displayed in this widget |
|---|
| 46 |
* @param array $attributes An array of HTML attributes to be merged with the default HTML attributes |
|---|
| 47 |
* @param array $errors An array of errors for the field |
|---|
| 48 |
* |
|---|
| 49 |
* @return string An HTML tag string |
|---|
| 50 |
* |
|---|
| 51 |
* @see sfWidgetForm |
|---|
| 52 |
*/ |
|---|
| 53 |
public function render($name, $value = null, $attributes = array(), $errors = array()) |
|---|
| 54 |
{ |
|---|
| 55 |
$values = array_merge(array('text' => '', 'is_empty' => false), is_array($value) ? $value : array()); |
|---|
| 56 |
|
|---|
| 57 |
return strtr($this->getOption('template'), array( |
|---|
| 58 |
'%input%' => $this->renderTag('input', array_merge(array('type' => 'text', 'id' => $this->generateId($name), 'name' => $name.'[text]', 'value' => $values['text']), $attributes)), |
|---|
| 59 |
'%empty_checkbox%' => $this->getOption('with_empty') ? $this->renderTag('input', array('type' => 'checkbox', 'name' => $name.'[is_empty]', 'checked' => $values['is_empty'] ? 'checked' : '')) : '', |
|---|
| 60 |
'%empty_label%' => $this->getOption('with_empty') ? $this->renderContentTag('label', $this->getOption('empty_label'), array('for' => $this->generateId($name.'[is_empty]'))) : '', |
|---|
| 61 |
)); |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|