You are here

public function LanguageSelectWidget::massageFormValues in Custom Language field 8

@inheritdoc

Overrides WidgetBase::massageFormValues

File

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

Class

LanguageSelectWidget
Plugin implementation of the 'language_select' widget.

Namespace

Drupal\languagefield\Plugin\Field\FieldWidget

Code

public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
  $values = parent::massageFormValues($values, $form, $form_state);

  // Convert the values to real language codes,
  // but ONLY on Entity form, NOT in the 'field settings - default value'.
  $build_info = $form_state
    ->getBuildInfo();
  if (isset($build_info['form_id']) && $build_info['form_id'] !== 'field_config_edit_form') {
    foreach ($values as &$value) {
      $value['value'] = LanguageItem::getLanguageConfigurationValues($value['value']);
    }
  }
  return $values;
}