[5.x] Add gallery grouping settings

Created on 4 August 2022, over 2 years ago
Updated 14 June 2023, over 1 year ago

Problem/Motivation

The original issue with a first approach was: Add gallery grouping options Closed: won't fix
But that logic wasn't very flexible and we have to think about this very well.

Expected behaviour:
Grouping must be very flexible to allow for example grouping by page, entity, field, item, ... anywhere, for example using fences or a twig override or a setting.

Current behaviour:
Currently, we're looking for a photoswipe-gallery in JavaScript using .closest() around each photoswipe item. If a gallery around the photoswipe link is already existing, there's nothing left to do.
If there's no grouping, we're adding the wrapper around each single element in JS.

Why so complicated?
As JS runs late (for Photoswipe initialization), it's irrelevant where we set the class before. This is much more flexible as in former times, where it was set in PHP code.

Anyway, it would still be helpful if we COULD configure grouping by a setting.

The problem is, that the field formatter, by logic, can only set the grouping per field or per item, but not for levels above.
And we shouldn't set the behavior as a global setting, at it might depend per entity type or even field.

So this task is about discussing how to solve this most flexible for all possible kinds of photoswipe implementation, even custom ones.
Also we should have a look how similar modules solve this. For example

  • Colorbox
  • Lightbox
  • ...?

https://www.drupal.org/node/266126

Steps to reproduce

Proposed resolution

a) Add a setting in the field formatter (where you'd expect it), but set grouping disabled by default, so it can also be set at any other level using fences, twig or whatever. Maybe set "Global setting" as default to define this global default.
Options could be:

  • Use global setting (from settings page)
  • No grouping
  • Group by page
  • Group by entity
  • Group by field
  • Group by custom class (JS)

b) ??

Furthermore we should definitely remove the hard-coded photoswipe-gallery wrapper, which changes Drupals default field structure (in src/Plugin/Field/FieldFormatter/PhotoswipeFieldFormatter.php):

   if (!empty($items) && count($items) > 1) {
      // If there are more than 1 elements, add the gallery wrapper.
      // Otherwise this is done in javascript for more flexibility.
      $elements['#prefix'] = '<div class="photoswipe-gallery">';
      $elements['#suffix'] = '</div>';
    }

and makes it hard to overwrite the wrapping!
See https://git.drupalcode.org/project/photoswipe/-/commit/6d6c3efff936599db... (D7) and the major issue introduced that way: #3179987: Grouping & thereby navigation buttons missing in 2.x-beta6+ which should not happen again. Anyway we might solve it similarly in 5.x like in Drupal 7 at the end of the issue?

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Needs work

Version

5.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024