You are here

class LanguageConverter in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/language/src/LanguageConverter.php \Drupal\language\LanguageConverter
  2. 8 core/modules/language/src/ProxyClass/LanguageConverter.php \Drupal\language\ProxyClass\LanguageConverter
Same name and namespace in other branches
  1. 8.0 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 17
Contains \Drupal\language\LanguageConverter.

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

Namesort descending Modifiers Type Description Overrides
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.