1. sfWidgetFormChoiceBase.class.php
  2. /** * sfWidgetFormChoiceBase is the base class for all choice/select widgets * * @package symfony * @subpackage widget * @author Bernhard Schussek * @version SVN: $Id$ */
  3. abstract class sfWidgetFormChoiceBase extends sfWidgetForm
  4. {
  5. /**
  6. * Constructor.
  7. *
  8. * Available options:
  9. *
  10. * * choices: An array of possible choices (required)
  11. *
  12. * @param array $options An array of options
  13. * @param array $attributes An array of default HTML attributes
  14. *
  15. * @see sfWidgetForm
  16. */
  17. protected function configure($options = array(), $attributes = array())
  18. {
  19. $this->addRequiredOption('choices');
  20. }
  21. /**
  22. * Returns the translated choices configured for this widget
  23. *
  24. * @return array An array of strings
  25. */
  26. public function getChoices()
  27. {
  28. $choices = $this->getOption('choices');
  29. if ($choices instanceof sfCallable)
  30. {
  31. $choices = $choices->call();
  32. }
  33. $results = array();
  34. foreach ($choices as $key => $choice)
  35. {
  36. if (is_array($choice))
  37. {
  38. $results[$this->translate($key)] = $this->translateAll($choice);
  39. }
  40. else
  41. {
  42. $results[$key] = $this->translate($choice);
  43. }
  44. }
  45. return $results;
  46. }
  47. /**
  48. * Clones this object
  49. */
  50. public function __clone()
  51. {
  52. if ($this->getOption('choices') instanceof sfCallable)
  53. {
  54. $callable = $this->getOption('choices')->getCallable();
  55. if (is_array($callable) && $callable[0] instanceof self)
  56. {
  57. $callable[0] = $this;
  58. $this->setOption('choices', new sfCallable($callable));
  59. }
  60. }
  61. }
  62. }

Debug toolbar