public function EntityFormController::getFormLangcode

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

Overrides EntityFormControllerInterface::getFormLangcode

7 calls to EntityFormController::getFormLangcode()

File

drupal/core/lib/Drupal/Core/Entity/EntityFormController.php, line 220
Definition of 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
    ->getEntity($form_state);
  $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;
}