protected function InlineParagraphsWidget::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 InlineParagraphsWidget::getCurrentLangcode()
InlineParagraphsWidget::formElement in paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Uses a similar approach to populate a new translation.

File

paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1144

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference 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();
}