LanguageConverter.php

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

Namespace

Drupal\language

File

core/modules/language/src/LanguageConverter.php

View source
<?php

namespace Drupal\language;

use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Symfony\Component\Routing\Route;

/**
 * Converts parameters for upcasting entity IDs to full objects.
 */
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';
    }

}

Classes

Title Deprecated Summary
LanguageConverter Converts parameters for upcasting entity IDs to full objects.

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