Skip to content

Commit

Permalink
Issue #100: Check for a visible Paragraphs item before displaying the…
Browse files Browse the repository at this point in the history
… field.

Fixes #100.
  • Loading branch information
laryn committed Aug 30, 2024
1 parent 7635543 commit 595fe38
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions paragraphs.field_formatter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,34 @@ function paragraphs_field_formatter_view($entity_type, $entity, $field, $instanc
$display_view_mode = empty($display['settings']['view_mode']) ? 'full' : $display['settings']['view_mode'];
// Get view mode from field instance (if configured).
$view_mode = empty($instance['display'][$display_view_mode]['settings']['view_mode']) ? $display_view_mode : $instance['display'][$display_view_mode]['settings']['view_mode'];
$element['#theme_wrappers'] = array('paragraphs_items');
$element['#attributes']['class'][] = backdrop_clean_css_identifier('paragraphs-items');
$element['#attributes']['class'][] = backdrop_clean_css_identifier('paragraphs-items-view-mode-' . $view_mode);
$element['#attributes']['class'][] = backdrop_clean_css_identifier('paragraphs-items-field-' . $instance['field_name']);
$element['#paragraphs_items_view_mode'] = $view_mode;

$count = 0;
$show_field = FALSE;
foreach ($items as $delta => $item) {
if ($paragraph = paragraphs_field_get_entity($item)) {
$paragraph->setHostEntity($entity_type, $entity, $langcode);
if (entity_access('view', 'paragraphs_item', $paragraph)) {

// Enter the paragraph item itself.
$element[$delta]['entity'] = $paragraph->view($view_mode, $langcode);

}
if (!empty($instance['settings']['modal_admin'])) {
$element[$delta]['entity']['paragraphs_item'][$paragraph->item_id]['#modal_admin'] = 1;
if ($paragraph->status) {
$show_field = TRUE;
$paragraph->setHostEntity($entity_type, $entity, $langcode);
if (entity_access('view', 'paragraphs_item', $paragraph)) {
// Enter the paragraph item itself.
$element[$delta]['entity'] = $paragraph->view($view_mode, $langcode);
}
if (!empty($instance['settings']['modal_admin'])) {
$element[$delta]['entity']['paragraphs_item'][$paragraph->item_id]['#modal_admin'] = 1;
}
$element[$delta]['entity']['paragraphs_item'][$paragraph->item_id]['#in_preview'] = $in_preview;
}
$element[$delta]['entity']['paragraphs_item'][$paragraph->item_id]['#in_preview'] = $in_preview;
$count++;
}
}
if (!$show_field) {
// There are Paragraphs items, but none of them are visible.
return $element;
}
$element['#theme_wrappers'] = array('paragraphs_items');
$element['#attributes']['class'][] = backdrop_clean_css_identifier('paragraphs-items');
$element['#attributes']['class'][] = backdrop_clean_css_identifier('paragraphs-items-view-mode-' . $view_mode);
$element['#attributes']['class'][] = backdrop_clean_css_identifier('paragraphs-items-field-' . $instance['field_name']);
$element['#paragraphs_items_view_mode'] = $view_mode;

break;
}

Expand Down

0 comments on commit 595fe38

Please sign in to comment.