Counts the number of paragraphs in a certain mode in a form substructure.
array $widget_state: The widget state for the form substructure containing information about the paragraphs within.
string $mode: The mode to look for.
int The number of paragraphs is the given mode.
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;
}