public static function ParagraphsWidget::autocollapse

Returns a state with all paragraphs closed, if autocollapse is enabled.

Parameters

array $widget_state: The current widget state.

Return value

array The widget state altered by closing all paragraphs.

4 calls to ParagraphsWidget::autocollapse()
ParagraphsWidget::addMoreSubmit in paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
ParagraphsWidget::duplicateSubmit in paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
Creates a duplicate of the paragraph entity.
ParagraphsWidget::paragraphsConvertCancel in paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
The submit callback to cancel the paragraphs conversion.
ParagraphsWidget::paragraphsItemSubmit in paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php

File

paragraphs/src/Plugin/Field/FieldWidget/ParagraphsWidget.php, line 3011

Class

ParagraphsWidget
Plugin implementation of the 'entity_reference_revisions paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public static function autocollapse(array $widget_state) {
  if ($widget_state['real_item_count'] > 0 && $widget_state['autocollapse'] !== 'none') {
    foreach ($widget_state['paragraphs'] as $delta => $value) {
      if ($widget_state['paragraphs'][$delta]['mode'] === 'edit') {
        $widget_state['paragraphs'][$delta]['mode'] = 'closed';
      }
    }
  }
  return $widget_state;
}