Development

/branches/1.1/lib/widget/i18n/sfWidgetFormI18nSelectLanguage.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/widget/i18n/sfWidgetFormI18nSelectLanguage.class.php

Revision 11700, 1.7 kB (checked in by fabien, 6 years ago)

[1.1, 1.2] changed internal classes to always use the sfCultureInfo singleton

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfWidgetFormI18nSelectLanguage represents a language HTML select tag.
13  *
14  * @package    symfony
15  * @subpackage widget
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfWidgetFormI18nSelectLanguage extends sfWidgetFormSelect
20 {
21   /**
22    * Constructor.
23    *
24    * Available options:
25    *
26    *  * culture:   The culture to use for internationalized strings (required)
27    *  * languages: An array of language codes to use (ISO 639-1)
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
38     $this->addRequiredOption('culture');
39     $this->addOption('languages');
40
41     // populate choices with all languages
42     $culture = isset($options['culture']) ? $options['culture'] : 'en';
43
44     $languages = sfCultureInfo::getInstance($culture)->getLanguages();
45
46     // restrict languages to a sub-set
47     if (isset($options['languages']))
48     {
49       if ($problems = array_diff($options['languages'], array_keys($languages)))
50       {
51         throw new InvalidArgumentException(sprintf('The following languages do not exist: %s.', implode(', ', $problems)));
52       }
53
54       $languages = array_intersect_key($languages, array_flip($options['languages']));
55     }
56
57     asort($languages);
58
59     $this->setOption('choices', $languages);
60   }
61 }
62
Note: See TracBrowser for help on using the browser.