- public function addCollapsedSummary(paragraphs\Entity\Paragraph $paragraphs_entity) {
- $text_types = ['text_with_summary', 'text', 'text_long', 'list_string'];
- $summary = [];
- foreach ($paragraphs_entity->getFieldDefinitions() as $key => $value) {
- if ($value->getType() == 'image') {
- if ($paragraphs_entity->get($key)->entity) {
- foreach ($paragraphs_entity->get($key) as $image_key => $image_value) {
- if ($image_value->title != '') {
- $text = $image_value->title;
- }
- elseif ($image_value->alt != '') {
- $text = $image_value->alt;
- }
- elseif ($text = $image_value->entity->filename->value) {
- $text = $image_value->entity->filename->value;
- }
- if (strlen($text) > 50) {
- $text = strip_tags(substr($text, 0, 150));
- }
- $summary[] = $text;
- }
- }
- }
- if (in_array($value->getType(), $text_types)) {
- $text = $paragraphs_entity->get($key)->value;
- if (strlen($text) > 50) {
- $text = strip_tags(substr($text, 0, 150));
- }
- $summary[] = $text;
- }
- if ($field_type = $value->getType() == 'entity_reference_revisions') {
- if ($paragraphs_entity->get($key) && $paragraphs_entity->get($key)->entity) {
- $summary[] = $this->addCollapsedSummary($paragraphs_entity->get($key)->entity);
- }
+ 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++;