public function LayoutParagraphsWidget::editItemAjax 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 1846
Class
- LayoutParagraphsWidget
- Entity Reference with Layout field widget.
Namespace
Drupal\layout_paragraphs\Plugin\Field\FieldWidgetCode
public function editItemAjax(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']);
$entity_form = $widget_field['entity_form'];
$entity = $entity_form['#entity'];
$type = $entity
->getParagraphType();
$html_id = $this
->entityFormHtmlId($field_state);
$dialog_options = [
'dialogClass' => 'layout-paragraphs-dialog',
'modal' => TRUE,
'appendTo' => '#' . $this->wrapperId,
'width' => 800,
'drupalAutoButtons' => FALSE,
];
$response = new AjaxResponse();
if ($form_state
->hasAnyErrors()) {
$content = [
'status' => [
'#weight' => -100,
'#type' => 'status_messages',
],
];
$response
->addCommand(new OpenDialogCommand('#' . $html_id, $this
->t('Unexpected Error'), $content, $dialog_options));
$response
->addCommand(new LayoutParagraphsStateResetCommand('#' . $this->wrapperId));
}
else {
$response
->addCommand(new AppendCommand('#' . $this->wrapperId, '<div id="' . $html_id . '"></div>'));
$response
->addCommand(new OpenDialogCommand('#' . $html_id, $this
->t('Edit @type', [
'@type' => $type
->label(),
]), $entity_form, $dialog_options));
$response
->addCommand(new LayoutParagraphsStateResetCommand('#' . $this->wrapperId));
}
return $response;
}