Namespace
Drupal\rules\TypedData\Options
File
-
src/TypedData/Options/LanguageOptions.php
View source
<?php
namespace Drupal\rules\TypedData\Options;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LanguageOptions extends OptionsProviderBase implements ContainerInjectionInterface {
protected $languageManager;
public function __construct(LanguageManagerInterface $language_manager) {
$this->languageManager = $language_manager;
}
public static function create(ContainerInterface $container) {
return new static($container->get('language_manager'));
}
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 . ')';
}
asort($options);
return $options;
}
}
Classes
| Title |
Deprecated |
Summary |
| LanguageOptions |
|
Options provider to list all languages enabled on the site. |