You are here

public function MenuLinkWidget::extractFormValues in Menu Link (Field) 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldWidget/MenuLinkWidget.php \Drupal\menu_link\Plugin\Field\FieldWidget\MenuLinkWidget::extractFormValues()

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 WidgetBase::extractFormValues

File

src/Plugin/Field/FieldWidget/MenuLinkWidget.php, line 194

Class

MenuLinkWidget
Provides a widget for the menu_link field type.

Namespace

Drupal\menu_link\Plugin\Field\FieldWidget

Code

public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) : void {
  parent::extractFormValues($items, $form, $form_state);

  // Extract menu and parent menu link from single select element.
  foreach ($items as $delta => $item) {
    if (!empty($item->enabled) && !empty($item->menu_parent) && $item->menu_parent !== ':') {
      list($item->menu_name, $item->parent) = explode(':', $item->menu_parent, 2);
    }
    else {
      $item->title = '';
      $item->description = '';
      $item->menu_name = '';
      $item->parent = '';
    }
    unset($item->enabled, $item->menu_parent);
  }
}