1. sfWidgetFormFilterInput.class.php
  2. /** * sfWidgetFormFilterInput represents an HTML input tag used for filtering text. * * @package symfony * @subpackage widget * @author Fabien Potencier * @version SVN: $Id: sfWidgetFormFilterInput.class.php 24015 2009-11-16 13:33:34Z bschussek $ */
  3. class sfWidgetFormFilterInput extends sfWidgetForm
  4. {
  5. /**
  6. * Constructor.
  7. *
  8. * Available options:
  9. *
  10. * * with_empty: Whether to add the empty checkbox (true by default)
  11. * * empty_label: The label to use when using an empty checkbox
  12. * * template: The template to use to render the widget
  13. * Available placeholders: %input%, %empty_checkbox%, %empty_label%
  14. *
  15. * @param array $options An array of options
  16. * @param array $attributes An array of default HTML attributes
  17. *
  18. * @see sfWidgetForm
  19. */
  20. protected function configure($options = array(), $attributes = array())
  21. {
  22. $this->addOption('with_empty', true);
  23. $this->addOption('empty_label', 'is empty');
  24. $this->addOption('template', '%input%<br />%empty_checkbox% %empty_label%');
  25. }
  26. /**
  27. * @param string $name The element name
  28. * @param string $value The value displayed in this widget
  29. * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
  30. * @param array $errors An array of errors for the field
  31. *
  32. * @return string An HTML tag string
  33. *
  34. * @see sfWidgetForm
  35. */
  36. public function render($name, $value = null, $attributes = array(), $errors = array())
  37. {
  38. $values = array_merge(array('text' => '', 'is_empty' => false), is_array($value) ? $value : array());
  39. return strtr($this->getOption('template'), array(
  40. '%input%' => $this->renderTag('input', array_merge(array('type' => 'text', 'id' => $this->generateId($name), 'name' => $name.'[text]', 'value' => $values['text']), $attributes)),
  41. '%empty_checkbox%' => $this->getOption('with_empty') ? $this->renderTag('input', array('type' => 'checkbox', 'name' => $name.'[is_empty]', 'checked' => $values['is_empty'] ? 'checked' : '')) : '',
  42. '%empty_label%' => $this->getOption('with_empty') ? $this->renderContentTag('label', $this->translate($this->getOption('empty_label')), array('for' => $this->generateId($name.'[is_empty]'))) : '',
  43. ));
  44. }
  45. }

Debug toolbar