You are here

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

Form #process callback.

Attaches the behavior plugin forms.

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 386

Class

ComponentFormBase
Class LayoutParagraphsComponentFormBase.

Namespace

Drupal\layout_paragraphs\Form

Code

public function behaviorPluginsForm(array $element, FormStateInterface $form_state, array &$form) {
  $element['#type'] = 'container';
  $element['#attributes']['class'][] = 'lpb-behavior-plugins';
  foreach ($this
    ->getEnabledBehaviorPlugins() as $behavior_id => $behavior_plugin) {
    $element[$behavior_id] = [
      '#parents' => array_merge($element['#parents'], [
        $behavior_id,
      ]),
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'lpb-behavior-plugins__' . Html::cleanCssIdentifier($behavior_id),
        ],
      ],
    ];
    $subform_state = SubformState::createForSubform($element[$behavior_id], $form, $form_state);
    if ($behavior_form = $behavior_plugin
      ->buildBehaviorForm($this->paragraph, $element[$behavior_id], $subform_state)) {
      $element[$behavior_id] = $behavior_form;
    }
  }
  return $element;
}