public function EntityReferenceLayoutWidget::cancelItemSubmit in Entity Reference with Layout 8
Form submit handler - cancels editing an item and closes form.
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 1221
Class
- EntityReferenceLayoutWidget
- Entity Reference with Layout field widget.
Namespace
Drupal\entity_reference_layout\Plugin\Field\FieldWidgetCode
public function cancelItemSubmit(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);
// If canceling an item that hasn't been created yet, remove it.
if (!empty($widget_state['items'][$delta]['is_new'])) {
array_splice($widget_state['items'], $delta, 1);
$widget_state['items_count'] = count($widget_state['items']);
}
$widget_state['open_form'] = FALSE;
static::setWidgetState($parents, $this->fieldName, $form_state, $widget_state);
$form_state
->setRebuild();
}