You are here

protected function ContentEntity::updateLangcode in Commerce Core 8.2

Updates the entity langcode to match the form langcode.

Allows the user to select a different language through the langcode form element, which is then transferred to form state.

Performed only if the inline form doesn't have a langcode form element of its own.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.

array $inline_form: The inline form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

1 call to ContentEntity::updateLangcode()
ContentEntity::submitInlineForm in src/Plugin/Commerce/InlineForm/ContentEntity.php
Submits the inline form.

File

src/Plugin/Commerce/InlineForm/ContentEntity.php, line 103

Class

ContentEntity
Provides an inline form for managing a content entity.

Namespace

Drupal\commerce\Plugin\Commerce\InlineForm

Code

protected function updateLangcode(ContentEntityInterface $entity, array $inline_form, FormStateInterface $form_state) {
  $form_langcode = $form_state
    ->get('langcode');
  if (empty($form_langcode)) {

    // The top-level form is not a content entity form.
    return;
  }
  $langcode_key = $this
    ->getLangcodeKey($entity);

  // The inline form has a visible langcode element, don't override its value.
  if (isset($inline_form[$langcode_key]) && Element::isVisibleElement($inline_form[$langcode_key])) {
    return;
  }
  $entity_langcode = $entity
    ->get($langcode_key)->value;
  if ($entity_langcode != $form_langcode && !$entity
    ->hasTranslation($form_langcode)) {
    $entity
      ->set($langcode_key, $form_langcode);
  }
}