public function EntityFormController::getFormLangcode

Implements \Drupal\Core\Entity\EntityFormControllerInterface::getFormLangcode().

Overrides EntityFormControllerInterface::getFormLangcode

7 calls to EntityFormController::getFormLangcode()
EntityFormController::form in drupal/core/lib/Drupal/Core/Entity/EntityFormController.php
Returns the actual form array to be built.
EntityFormController::isDefaultFormLangcode in drupal/core/lib/Drupal/Core/Entity/EntityFormController.php
Implements \Drupal\Core\Entity\EntityFormControllerInterface::isDefaultFormLangcode().
EntityFormController::submitEntityLanguage in drupal/core/lib/Drupal/Core/Entity/EntityFormController.php
Handle possible entity language changes.
EntityFormControllerNG::buildEntity in drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
Overrides EntityFormController::buildEntity().
EntityFormControllerNG::form in drupal/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php
Overrides EntityFormController::form().

... See full list

File

drupal/core/lib/Drupal/Core/Entity/EntityFormController.php, line 310
Contains \Drupal\Core\Entity\EntityFormController.

Class

EntityFormController
Base class for entity form controllers.

Namespace

Drupal\Core\Entity

Code

public function getFormLangcode(array $form_state) {
  $entity = $this->entity;
  $translations = $entity
    ->getTranslationLanguages();
  if (!empty($form_state['langcode'])) {
    $langcode = $form_state['langcode'];
  }
  else {

    // If no form langcode was provided we default to the current content
    // language and inspect existing translations to find a valid fallback,
    // if any.
    $langcode = language(Language::TYPE_CONTENT)->langcode;
    $fallback = language_multilingual() ? language_fallback_get_candidates() : array();
    while (!empty($langcode) && !isset($translations[$langcode])) {
      $langcode = array_shift($fallback);
    }
  }

  // If the site is not multilingual or no translation for the given form
  // language is available, fall back to the entity language.
  return !empty($langcode) ? $langcode : $entity
    ->language()->langcode;
}