You are here

public function EntityReferenceLayoutWidget::elementAjax in Entity Reference with Layout 8

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/EntityReferenceLayoutWidget.php, line 1249

Class

EntityReferenceLayoutWidget
Entity Reference with Layout field widget.

Namespace

Drupal\entity_reference_layout\Plugin\Field\FieldWidget

Code

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);
  $erl_field = NestedArray::getValue($form, $field_state['array_parents']);
  $response = new AjaxResponse();
  $response
    ->addCommand(new ReplaceCommand('#' . $this->wrapperId, $erl_field));
  $response
    ->addCommand(new ErlStateResetCommand('#' . $this->wrapperId));
  return $response;
}