public function LayoutParagraphsWidget::elementAjax in Layout Paragraphs 1.0.x
Ajax callback to return the entire ERL element.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
\Drupal\Core\Ajax\AjaxResponse The Ajax Response.
File
- src/
Plugin/ Field/ FieldWidget/ LayoutParagraphsWidget.php, line 1762
Class
- LayoutParagraphsWidget
- Entity Reference with Layout field widget.
Namespace
Drupal\layout_paragraphs\Plugin\Field\FieldWidgetCode
public function elementAjax(array $form, FormStateInterface $form_state) {
$element = $form_state
->getTriggeringElement();
$parents = $element['#element_parents'];
$field_state = static::getWidgetState($parents, $this->fieldName, $form_state);
$widget_field = NestedArray::getValue($form, $field_state['array_parents']);
$html_id = $this
->entityFormHtmlId($field_state);
$response = new AjaxResponse();
$response
->addCommand(new CloseDialogCommand('#' . $html_id));
$response
->addCommand(new ReplaceCommand('#' . $this->wrapperId, $widget_field));
$response
->addCommand(new LayoutParagraphsStateResetCommand('#' . $this->wrapperId));
return $response;
}