You are here

public function LayoutParagraphsBehavior::submitBehaviorForm in Layout Paragraphs 2.0.x

File

src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php, line 173

Class

LayoutParagraphsBehavior
Provides a way to define grid based layouts.

Namespace

Drupal\layout_paragraphs\Plugin\paragraphs\Behavior

Code

public function submitBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) {
  $filtered_values = $this
    ->filterBehaviorFormSubmitValues($paragraph, $form, $form_state);
  $plugin_instance = $this->layoutPluginManager
    ->createInstance($form_state
    ->getValue('layout'), $form_state
    ->getValue('config'));
  if ($plugin_form = $this
    ->getLayoutPluginForm($plugin_instance)) {
    $subform_state = SubformState::createForSubform($form['config'], $form, $form_state);
    $plugin_form
      ->submitConfigurationForm($form['config'], $subform_state);
    $filtered_values['config'] = $plugin_form
      ->getConfiguration();
  }

  // Merge existing behavior settings.
  $behavior_settings = $paragraph
    ->getAllBehaviorSettings();
  $existing_settings = $behavior_settings[$this
    ->getPluginId()] ?? [];
  $filtered_values = $filtered_values + $existing_settings;

  // Set the updated behavior settings.
  $paragraph
    ->setBehaviorSettings($this
    ->getPluginId(), $filtered_values);
}