You are here

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

Ajax callback to return a layout plugin configuration form.

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 1272

Class

EntityReferenceLayoutWidget
Entity Reference with Layout field widget.

Namespace

Drupal\entity_reference_layout\Plugin\Field\FieldWidget

Code

public function buildLayoutConfigurationFormAjax(array $form, FormStateInterface $form_state) {
  $element = $form_state
    ->getTriggeringElement();
  $parents = $element['#array_parents'];
  $parents = array_splice($parents, 0, -2);
  $parents = array_merge($parents, [
    'layout_plugin_form',
  ]);
  $response = new AjaxResponse();
  if ($layout_plugin_form = NestedArray::getValue($form, $parents)) {
    $response
      ->addCommand(new ReplaceCommand('#layout-config', $layout_plugin_form));
    $response
      ->addCommand(new ErlStateResetCommand('#' . $this->wrapperId));
  }
  return $response;
}