You are here

class LanguageConverter in Drupal 10

Same name in this branch
  1. 10 core/modules/language/src/LanguageConverter.php \Drupal\language\LanguageConverter
  2. 10 core/modules/language/src/ProxyClass/LanguageConverter.php \Drupal\language\ProxyClass\LanguageConverter
Same name and namespace in other branches
  1. 8 core/modules/language/src/LanguageConverter.php \Drupal\language\LanguageConverter
  2. 9 core/modules/language/src/LanguageConverter.php \Drupal\language\LanguageConverter

Converts parameters for upcasting entity IDs to full objects.

Hierarchy

  • class \Drupal\language\LanguageConverter implements \Drupal\Core\ParamConverter\ParamConverterInterface

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