1. sfWidgetFormInputCheckbox.class.php
  2. /** * sfWidgetFormInputCheckbox represents an HTML checkbox tag. * * @package symfony * @subpackage widget * @author Fabien Potencier * @version SVN: $Id: sfWidgetFormInputCheckbox.class.php 21908 2009-09-11 12:06:21Z fabien $ */
  3. class sfWidgetFormInputCheckbox extends sfWidgetFormInput
  4. {
  5. /**
  6. * Constructor.
  7. *
  8. * Available options:
  9. *
  10. * - value_attribute_value: The "value" attribute value to set for the checkbox
  11. *
  12. * @param array $options An array of options
  13. * @param array $attributes An array of default HTML attributes
  14. *
  15. * @see sfWidgetFormInput
  16. */
  17. public function __construct($options = array(), $attributes = array())
  18. {
  19. $this->addOption('value_attribute_value');
  20. parent::__construct($options, $attributes);
  21. }
  22. /**
  23. * @param array $options An array of options
  24. * @param array $attributes An array of default HTML attributes
  25. *
  26. * @see sfWidgetFormInput
  27. */
  28. protected function configure($options = array(), $attributes = array())
  29. {
  30. parent::configure($options, $attributes);
  31. $this->setOption('type', 'checkbox');
  32. if (isset($attributes['value']))
  33. {
  34. $this->setOption('value_attribute_value', $attributes['value']);
  35. }
  36. }
  37. /**
  38. * @param string $name The element name
  39. * @param string $value The this widget is checked if value is not null
  40. * @param array $attributes An array of HTML attributes to be merged with the default HTML attributes
  41. * @param array $errors An array of errors for the field
  42. *
  43. * @return string An HTML tag string
  44. *
  45. * @see sfWidgetForm
  46. */
  47. public function render($name, $value = null, $attributes = array(), $errors = array())
  48. {
  49. if (null !== $value && $value !== false)
  50. {
  51. $attributes['checked'] = 'checked';
  52. }
  53. if (!isset($attributes['value']) && null !== $this->getOption('value_attribute_value'))
  54. {
  55. $attributes['value'] = $this->getOption('value_attribute_value');
  56. }
  57. return parent::render($name, null, $attributes, $errors);
  58. }
  59. }

Debug toolbar