public static function EntityqueueDragtableWidget::addItemAjax in Entityqueue 8
Ajax callback for the "Add item" button.
File
- src/
Plugin/ Field/ FieldWidget/ EntityqueueDragtableWidget.php, line 332
Class
- EntityqueueDragtableWidget
- Plugin implementation of the 'entityqueue_dragtable' widget.
Namespace
Drupal\entityqueue\Plugin\Field\FieldWidgetCode
public static function addItemAjax(array $form, FormStateInterface $form_state) {
$button = $form_state
->getTriggeringElement();
// Go two levels up in the form, to the widgets container.
$element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -2));
// Remove the submitted value from the 'Add item' textfield.
$element['add_more']['new_item']['target_id']['#value'] = NULL;
// Add a DIV around the delta receiving the Ajax effect.
$delta = $element['#max_delta'];
$element[$delta]['#prefix'] = '<div class="ajax-new-content">' . (isset($element[$delta]['#prefix']) ? $element[$delta]['#prefix'] : '');
$element[$delta]['#suffix'] = (isset($element[$delta]['#suffix']) ? $element[$delta]['#suffix'] : '') . '</div>';
return $element;
}