class LanguageConverter

Same name in this branch
  1. 10 core/modules/language/src/ProxyClass/LanguageConverter.php \Drupal\language\ProxyClass\LanguageConverter
Same name in other branches
  1. 9 core/modules/language/src/ProxyClass/LanguageConverter.php \Drupal\language\ProxyClass\LanguageConverter
  2. 9 core/modules/language/src/LanguageConverter.php \Drupal\language\LanguageConverter
  3. 8.9.x core/modules/language/src/ProxyClass/LanguageConverter.php \Drupal\language\ProxyClass\LanguageConverter
  4. 8.9.x core/modules/language/src/LanguageConverter.php \Drupal\language\LanguageConverter
  5. 11.x core/modules/language/src/ProxyClass/LanguageConverter.php \Drupal\language\ProxyClass\LanguageConverter
  6. 11.x core/modules/language/src/LanguageConverter.php \Drupal\language\LanguageConverter

Converts parameters for upcasting entity IDs to full objects.

Hierarchy

Expanded class hierarchy of LanguageConverter

1 string reference to 'LanguageConverter'
language.services.yml in core/modules/language/language.services.yml
core/modules/language/language.services.yml
1 service uses LanguageConverter
language_converter in core/modules/language/language.services.yml
Drupal\language\LanguageConverter

File

core/modules/language/src/LanguageConverter.php, line 12

Namespace

Drupal\language
View source
class LanguageConverter implements ParamConverterInterface {
    
    /**
     * The language manager.
     *
     * @var \Drupal\Core\Language\LanguageManagerInterface
     */
    protected $languageManager;
    
    /**
     * Constructs a new LanguageConverter.
     *
     * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
     *   The language manager.
     */
    public function __construct(LanguageManagerInterface $language_manager) {
        $this->languageManager = $language_manager;
    }
    
    /**
     * {@inheritdoc}
     */
    public function convert($value, $definition, $name, array $defaults) {
        if (!empty($value)) {
            return $this->languageManager
                ->getLanguage($value);
        }
        return NULL;
    }
    
    /**
     * {@inheritdoc}
     */
    public function applies($definition, $name, Route $route) {
        return !empty($definition['type']) && $definition['type'] == 'language';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
LanguageConverter::$languageManager protected property The language manager.
LanguageConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
LanguageConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
LanguageConverter::__construct public function Constructs a new LanguageConverter.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.