You are here

public function LayoutBuilderWidget::extractFormValues in Layout Builder Symmetric Translations 8

Extracts field values from submitted form values.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values. This parameter is altered by reference to receive the incoming form values.

array $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.

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

Overrides LayoutBuilderWidget::extractFormValues

File

src/Plugin/Field/FieldWidget/LayoutBuilderWidget.php, line 19

Class

LayoutBuilderWidget
Extended LayoutBuilderWidget to extract the value translation field.

Namespace

Drupal\layout_builder_st\Plugin\Field\FieldWidget

Code

public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) {
  $field_name = $this->fieldDefinition
    ->getName();
  if ($field_name === OverridesSectionStorage::FIELD_NAME) {
    parent::extractFormValues($items, $form, $form_state);
    return;
  }
  if (!$form_state
    ->isValidationComplete()) {
    return;
  }
  $section_storage = $this
    ->getSectionStorage($form_state);
  if ($field_name === OverridesSectionStorage::TRANSLATED_CONFIGURATION_FIELD_NAME && $section_storage instanceof TranslatableSectionStorageInterface) {

    // The translated configuration is stored in single value field because it
    // stores configuration for components in all sections.
    $items
      ->set(0, $section_storage
      ->getTranslatedConfiguration());
  }
  else {
    throw new \LogicException("Widget used with unexpected field, {$field_name} for section storage: " . $section_storage
      ->getStorageType());
  }
}