public function LayoutParagraphsWidget::removeItemConfirmSubmit in Layout Paragraphs 1.0.x
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/ LayoutParagraphsWidget.php, line 1576
Class
- LayoutParagraphsWidget
- Entity Reference with Layout field widget.
Namespace
Drupal\layout_paragraphs\Plugin\Field\FieldWidgetCode
public function removeItemConfirmSubmit(array $form, FormStateInterface $form_state) {
$element = $form_state
->getTriggeringElement();
$element_parents = $element['#parents'];
$remove_form_parents = array_splice($element_parents, 0, -2);
$nested_items_path = array_merge($remove_form_parents, [
'nested_items',
]);
$nested_items_value = $form_state
->getValue($nested_items_path);
$uuid = $element['#uuid'];
$parents = $element['#element_parents'];
$delta = $element['#delta'];
$widget_state = static::getWidgetState($parents, $this->fieldName, $form_state);
if ($nested_items_value == 'remove') {
$this
->removeChildren($widget_state['items'], $uuid);
}
unset($widget_state['items'][$delta]['entity']);
$widget_state['remove_item'] = FALSE;
static::setWidgetState($parents, $this->fieldName, $form_state, $widget_state);
$form_state
->setRebuild();
}