protected function InlineParagraphsWidget::getNumberOfParagraphsInMode

Counts the number of paragraphs in a certain mode in a form substructure.

Parameters

array $widget_state: The widget state for the form substructure containing information about the paragraphs within.

string $mode: The mode to look for.

Return value

int The number of paragraphs is the given mode.

1 call to InlineParagraphsWidget::getNumberOfParagraphsInMode()
InlineParagraphsWidget::multipleElementValidate in paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Special handling to validate form elements with multiple values.

File

paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1503

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function getNumberOfParagraphsInMode(array $widget_state, $mode) {
  if (!isset($widget_state['paragraphs'])) {
    return 0;
  }
  $paragraphs_count = 0;
  foreach ($widget_state['paragraphs'] as $paragraph) {
    if ($paragraph['mode'] == $mode) {
      $paragraphs_count++;
    }
  }
  return $paragraphs_count;
}