|
Revision 11700, 1.7 kB
(checked in by fabien, 5 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 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 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 |
|
|---|
| 42 |
$culture = isset($options['culture']) ? $options['culture'] : 'en'; |
|---|
| 43 |
|
|---|
| 44 |
$languages = sfCultureInfo::getInstance($culture)->getLanguages(); |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 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 |
|
|---|