protected function ParagraphsWidget::getCurrentLangcode

Gets current language code from the form state or item.

Since the paragraph field is not set as translatable, the item language code is set to the source language. The intended translation language is only accessibly through the form state.

Parameters

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

\Drupal\Core\Field\FieldItemListInterface $items: The field item list.

Return value

string The language code.

1 call to ParagraphsWidget::getCurrentLangcode()
ParagraphsWidget::formElement in paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Uses a similar approach to populate a new translation.

File

paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 1964

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function getCurrentLangcode(FormStateInterface $form_state, FieldItemListInterface $items) {
  return $form_state
    ->has('langcode') ? $form_state
    ->get('langcode') : $items
    ->getEntity()
    ->language()
    ->getId();
}