public function EntityFormController::getFormLangcode

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

Overrides EntityFormControllerInterface::getFormLangcode

7 calls to EntityFormController::getFormLangcode()
CommentFormController::submit in drupal/core/modules/comment/lib/Drupal/comment/CommentFormController.php
Overrides Drupal\Core\Entity\EntityFormController::submit().
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 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().

... See full list

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;
}