sfWidgetFormI18nSelectLanguage.class.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfWidgetFormI18nSelectLanguage represents a language HTML select tag.
  11. *
  12. * @package symfony
  13. * @subpackage widget
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfWidgetFormI18nSelectLanguage.class.php 11842 2008-09-29 10:53:28Z fabien $
  16. */
  17. class sfWidgetFormI18nSelectLanguage extends sfWidgetFormSelect
  18. {
  19. /**
  20. * Constructor.
  21. *
  22. * Available options:
  23. *
  24. * * culture: The culture to use for internationalized strings (required)
  25. * * languages: An array of language codes to use (ISO 639-1)
  26. * * add_empty: Whether to add a first empty value or not (false by default)
  27. * If the option is not a Boolean, the value will be used as the text value
  28. *
  29. * @param array $options An array of options
  30. * @param array $attributes An array of default HTML attributes
  31. *
  32. * @see sfWidgetFormSelect
  33. */
  34. protected function configure($options = array(), $attributes = array())
  35. {
  36. parent::configure($options, $attributes);
  37. $this->addRequiredOption('culture');
  38. $this->addOption('languages');
  39. $this->addOption('add_empty', false);
  40. // populate choices with all languages
  41. $culture = isset($options['culture']) ? $options['culture'] : 'en';
  42. $languages = sfCultureInfo::getInstance($culture)->getLanguages(isset($options['languages']) ? $options['languages'] : null);
  43. $addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
  44. if (false !== $addEmpty)
  45. {
  46. $languages = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $languages);
  47. }
  48. $this->setOption('choices', $languages);
  49. }
  50. }