You are here

protected function PollChoiceDefaultWidget::getCurrentLangcode in Poll 8

Gets current language code from the form state or item.

Since the choice 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 items object.

Return value

string The language code to be used.

1 call to PollChoiceDefaultWidget::getCurrentLangcode()
PollChoiceDefaultWidget::formElement in src/Plugin/Field/FieldWidget/PollChoiceDefaultWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/PollChoiceDefaultWidget.php, line 84

Class

PollChoiceDefaultWidget
Plugin implementation of the 'poll_choice_default' widget.

Namespace

Drupal\poll\Plugin\Field\FieldWidget

Code

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