You are here

protected function ComponentFormBase::initFormLangcodes in Layout Paragraphs 2.0.x

Initializes form language code values.

See Drupal\Core\Entity\ContentEntityForm.

Parameters

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

1 call to ComponentFormBase::initFormLangcodes()
ComponentFormBase::buildComponentForm in src/Form/ComponentFormBase.php
Builds a component (paragraph) edit form.

File

src/Form/ComponentFormBase.php, line 525

Class

ComponentFormBase
Class LayoutParagraphsComponentFormBase.

Namespace

Drupal\layout_paragraphs\Form

Code

protected function initFormLangcodes(FormStateInterface $form_state) {

  // Store the entity default language to allow checking whether the form is
  // dealing with the original entity or a translation.
  if (!$form_state
    ->has('entity_default_langcode')) {
    $form_state
      ->set('entity_default_langcode', $this->paragraph
      ->getUntranslated()
      ->language()
      ->getId());
  }

  // This value might have been explicitly populated to work with a particular
  // entity translation. If not we fall back to the most proper language based
  // on contextual information.
  if (!$form_state
    ->has('langcode')) {

    // Imply a 'view' operation to ensure users edit entities in the same
    // language they are displayed. This allows to keep contextual editing
    // working also for multilingual entities.
    $form_state
      ->set('langcode', $this->entityRepository
      ->getTranslationFromContext($this->paragraph)
      ->language()
      ->getId());
  }
}