class LanguageOptions
Options provider to list all languages enabled on the site.
Hierarchy
- class \Drupal\rules\TypedData\Options\OptionsProviderBase implements \Drupal\Core\TypedData\OptionsProviderInterface uses \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\rules\TypedData\Options\LanguageOptions extends \Drupal\rules\TypedData\Options\OptionsProviderBase implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface
Expanded class hierarchy of LanguageOptions
1 file declares its use of LanguageOptions
- OptionsProviderTest.php in tests/
src/ Functional/ OptionsProvider/ OptionsProviderTest.php
File
-
src/
TypedData/ Options/ LanguageOptions.php, line 14
Namespace
Drupal\rules\TypedData\OptionsView source
class LanguageOptions extends OptionsProviderBase implements ContainerInjectionInterface {
/**
* The language_manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a LanguageOptions object.
*
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language_manager service.
*/
public function __construct(LanguageManagerInterface $language_manager) {
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('language_manager'));
}
/**
* {@inheritdoc}
*/
public function getPossibleOptions(AccountInterface $account = NULL) {
$languages = $this->languageManager
->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
$default = $this->languageManager
->getDefaultLanguage()
->getId();
$options = [
LanguageInterface::LANGCODE_NOT_SPECIFIED => $this->t('Not specified'),
];
foreach ($languages as $langcode => $language) {
$options[$langcode] = $language->getName() . ($langcode == $default ? ' - default' : '') . ' (' . $langcode . ')';
}
// Sort the result by value for ease of locating and selecting.
asort($options);
return $options;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
LanguageOptions::$languageManager | protected | property | The language_manager service. | ||
LanguageOptions::create | public static | function | Instantiates a new instance of this class. | Overrides ContainerInjectionInterface::create | |
LanguageOptions::getPossibleOptions | public | function | Returns an array of possible values with labels for display. | Overrides OptionsProviderInterface::getPossibleOptions | |
LanguageOptions::__construct | public | function | Constructs a LanguageOptions object. | ||
OptionsProviderBase::getPossibleValues | public | function | Returns an array of possible values. | Overrides OptionsProviderInterface::getPossibleValues | |
OptionsProviderBase::getSettableOptions | public | function | Returns an array of settable values with labels for display. | Overrides OptionsProviderInterface::getSettableOptions | |
OptionsProviderBase::getSettableValues | public | function | Returns an array of settable values. | Overrides OptionsProviderInterface::getSettableValues | |
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. |