Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DROOP-1074 fixed gallery display in case of several galleries on one page. #875

Open
wants to merge 5 commits into
base: 4.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ content:
colorbox_node_style: gallery_thumbnail
colorbox_node_style_first: ''
colorbox_image_style: gallery_fullscreen
colorbox_gallery: page
colorbox_gallery: custom
colorbox_gallery_custom: ''
colorbox_caption: auto
colorbox_caption_custom: ''
Expand Down
34 changes: 34 additions & 0 deletions modules/custom/d_p_gallery/d_p_gallery.module
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,37 @@ declare(strict_types = 1);
function d_p_gallery_d_p_centered_ckeditor_widget_paragraphs(array &$paragraph_types) {
$paragraph_types[] = 'd_p_gallery';
}

/**
* Prepares variables for colorbox formatter templates.
*
* @param array $variables
* An associative array containing:
* - item: An ImageItem object.
* - item_attributes: An optional associative array of html attributes to be
* placed in the img tag.
* - entity: An entity object.
* - settings: Formatter settings array.
*/
function d_p_gallery_preprocess_colorbox_formatter(array &$variables) {
if ($variables['settings']['colorbox_gallery'] !== 'custom') {
return;
}

$field_parent = $variables['item']->getEntity();

if (!$field_parent) {
return;
}

$referring_item = $field_parent->_referringItem?->getEntity();

if (!$referring_item) {
return;
}

$parent_id = $referring_item->get('id')->getString();

$variables['#cache']['max-age'] = 0;
$variables['attributes']['data-colorbox-gallery'] = $variables['attributes']['data-colorbox-gallery'] . "-" . $parent_id;
}