You are here

public function EntityReferenceLayoutWidget::removeItemConfirmSubmit in Entity Reference with Layout 8

Form submit handler - removes/deletes an item.

Parameters

array $form: The form array.

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

File

src/Plugin/Field/FieldWidget/EntityReferenceLayoutWidget.php, line 1091

Class

EntityReferenceLayoutWidget
Entity Reference with Layout field widget.

Namespace

Drupal\entity_reference_layout\Plugin\Field\FieldWidget

Code

public function removeItemConfirmSubmit(array $form, FormStateInterface $form_state) {
  $element = $form_state
    ->getTriggeringElement();
  $parents = $element['#element_parents'];
  $delta = $element['#delta'];
  $widget_state = static::getWidgetState($parents, $this->fieldName, $form_state);
  unset($widget_state['items'][$delta]['entity']);
  unset($widget_state['remove_item']);
  static::setWidgetState($parents, $this->fieldName, $form_state, $widget_state);
  $form_state
    ->setRebuild();
}