1. sfWidgetFormI18nChoiceCountry.class.php
  2. /** * sfWidgetFormI18nChoiceCountry represents a country choice widget. * * @package symfony * @subpackage widget * @author Fabien Potencier * @version SVN: $Id: sfWidgetFormI18nChoiceCountry.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. class sfWidgetFormI18nChoiceCountry extends sfWidgetFormChoice
  4. {
  5. /**
  6. * Constructor.
  7. *
  8. * Available options:
  9. *
  10. * * culture: The culture to use for internationalized strings
  11. * * countries: An array of country codes to use (ISO 3166)
  12. * * add_empty: Whether to add a first empty value or not (false by default)
  13. * If the option is not a Boolean, the value will be used as the text value
  14. *
  15. * @param array $options An array of options
  16. * @param array $attributes An array of default HTML attributes
  17. *
  18. * @see sfWidgetFormChoice
  19. */
  20. protected function configure($options = array(), $attributes = array())
  21. {
  22. parent::configure($options, $attributes);
  23. $this->addOption('culture');
  24. $this->addOption('countries');
  25. $this->addOption('add_empty', false);
  26. // populate choices with all countries
  27. $culture = isset($options['culture']) ? $options['culture'] : 'en';
  28. $countries = sfCultureInfo::getInstance($culture)->getCountries(isset($options['countries']) ? $options['countries'] : null);
  29. $addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
  30. if (false !== $addEmpty)
  31. {
  32. $countries = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $countries);
  33. }
  34. $this->setOption('choices', $countries);
  35. }
  36. }

Debug toolbar