You are here

public function ComponentFormBase::layoutParagraphsBehaviorForm in Layout Paragraphs 2.0.x

Form #process callback.

Renders the layout paragraphs behavior form for layout selection.

Parameters

array $element: The form element.

Drupal\Core\Form\FormStateInterface $form_state: The form state.

array $form: The complete form array.

Return value

array The processed element.

File

src/Form/ComponentFormBase.php, line 355

Class

ComponentFormBase
Class LayoutParagraphsComponentFormBase.

Namespace

Drupal\layout_paragraphs\Form

Code

public function layoutParagraphsBehaviorForm(array $element, FormStateInterface $form_state, array &$form) {
  $layout_paragraphs_plugin = $this->paragraphType
    ->getEnabledBehaviorPlugins()['layout_paragraphs'];
  $subform_state = SubformState::createForSubform($element, $form, $form_state);
  if ($layout_paragraphs_plugin_form = $layout_paragraphs_plugin
    ->buildBehaviorForm($this->paragraph, $element, $subform_state)) {
    $element = $layout_paragraphs_plugin_form;

    // Adjust the Ajax callback to include the entire layout paragraphs form.
    $element_id = Html::getId('layout-paragraphs-element');
    $element['#prefix'] = '<div id="' . $element_id . '">';
    $element['#suffix'] = '</div>';
    $element['layout']['#ajax']['callback'] = [
      $this,
      'ajaxCallback',
    ];
    $element['layout']['#ajax']['wrapper'] = $element_id;
  }
  return $element;
}