You are here

public static function ParagraphsWidget::changeAllEditModeSubmit in Paragraphs 8

Loops through all paragraphs and change mode for each paragraph instance.

Parameters

array $form: Current form state.

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

File

src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 2627

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public static function changeAllEditModeSubmit(array $form, FormStateInterface $form_state) {
  $submit = ParagraphsWidget::getSubmitElementInfo($form, $form_state, ParagraphsWidget::ACTION_POSITION_HEADER);

  // Change edit mode for each paragraph.
  foreach ($submit['widget_state']['paragraphs'] as $delta => &$paragraph) {
    if ($submit['widget_state']['paragraphs'][$delta]['mode'] !== 'remove') {
      $submit['widget_state']['paragraphs'][$delta]['mode'] = $submit['button']['#paragraphs_mode'];
      if (!empty($submit['button']['#paragraphs_show_warning'])) {
        $submit['widget_state']['paragraphs'][$delta]['show_warning'] = $submit['button']['#paragraphs_show_warning'];
      }
    }
  }
  if ($submit['widget_state']['autocollapse_default'] == 'all') {
    if ($submit['button']['#paragraphs_mode'] === 'edit') {
      $submit['widget_state']['autocollapse'] = 'none';
    }
    elseif ($submit['button']['#paragraphs_mode'] === 'closed') {
      $submit['widget_state']['autocollapse'] = 'all';
    }
  }
  static::setWidgetState($submit['parents'], $submit['field_name'], $form_state, $submit['widget_state']);
  $form_state
    ->setRebuild();
}