Replace hardcoded Media Photoswipe view mode with configurable formatter

Created on 22 July 2025, 3 months ago

Problem/Motivation

The Media Gallery module uses a custom Media Photoswipe view mode to display the image field (`field_images`) on gallery entities. This view mode:
- Is not easily customizable by site builders from the UI
- Is not using the existing configurable field formatter provided by [Photoswipe field formatter]( https://www.drupal.org/project/photoswipe β†’ ).

Steps to reproduce

1. Install and enable the Media Gallery module.
2. Create a media gallery entity and add media items with images.
3. Go to the Structure -> Media Gallery -> Manage View Display
4. Observe that the "Rendered Entity" Format and "Media Photoswipe View Mode" is used to render `field_images` but this does not expose any configurability for Photoswipe to the user.
5. Switch the Format to the the [Photoswipe field formatter]( https://www.drupal.org/project/photoswipe β†’ ) module.
6. Save the formatting
7. Go to a gallery and observe that the photoswipe gallery is not rendered correctly.

Proposed resolution

- Update the default configuration for `field_images` to use the `photoswipe_field` formatter plugin instead of the `Rendered Entity` formatter.

- Implement a `hook_post_update_NAME()` function that:
- Scans all `entity_view_display` configs for `media_gallery` entities.
- Replaces the formatter for `field_images` with `photoswipe_field` if it still uses the default `Media Photoswipe` view
mode and Rendered Entity formatter.
- Applies reasonable default settings for the Photoswipe formatter (e.g., image style).
- If present and unused, delete the `Media Photoswipe" view mode and its associated display config to avoid conflicts.

Remaining tasks

- [x] Open this issue.
- [ ] Submit merge request/patch
- [ ] Code Review

User interface changes

No user-facing UI changes. Admins may notice the Photoswipe formatter used by default on the `field_images` field when editing view displays.

API changes

None.

Data model changes

No changes to field storage or entity schema. The update modifies field display configuration and removes a view mode config entity (`core.entity_view_display.media.image.media_photoswipe`, `core.entity_view_display.media.media_photoswipe`)

✨ Feature request
Status

Active

Version

3.0

Component

Default

Created by

πŸ‡ΊπŸ‡ΈUnited States circuitcipher

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

Merge Requests

Comments & Activities

  • Issue created by @circuitcipher
  • Pipeline finished with Failed
    3 months ago
    #554214
  • Pipeline finished with Running
    3 months ago
    #554272
  • Pipeline finished with Success
    3 months ago
    #554287
  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher
  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher
  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    I am currently working on fixing PHPCS errors and hope to push them today.

  • Pipeline finished with Success
    3 months ago
    Total: 194s
    #556382
  • Pipeline finished with Success
    3 months ago
    Total: 210s
    #556404
  • Pipeline finished with Success
    3 months ago
    Total: 168s
    #556409
  • Pipeline finished with Success
    3 months ago
    Total: 140s
    #556416
  • Pipeline finished with Success
    3 months ago
    Total: 136s
    #556419
  • Pipeline finished with Success
    3 months ago
    Total: 152s
    #556853
  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    These changes should be complete at this point. I am just requesting a code review/testing as this is making some sweeping changes and I'm relatively new to the Drupal development space.

  • Pipeline finished with Success
    3 months ago
    #556981
  • First commit to issue fork.
  • πŸ‡§πŸ‡ΎBelarus ivnish

    I tested this patch manually.

    1) The reverse order is broken with pager (reverse works only for current (first?) page)

    2) The new pager shows 12 images instead of 9. This can break existing sites.

    When you fixed this, I will test upgrade from existing sites

  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    Thank you so much for your timely review! I will work on resolving these issues.

  • πŸ‡§πŸ‡ΎBelarus ivnish

    This issue also has pager issues. If I understand correctly we need to commit another issue first

  • Pipeline finished with Failed
    3 months ago
    Total: 243s
    #559015
  • Pipeline finished with Success
    3 months ago
    Total: 153s
    #559054
  • Pipeline finished with Success
    3 months ago
    Total: 142s
    #559057
  • Pipeline finished with Success
    3 months ago
    Total: 144s
    #559060
  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    1) The reverse order is broken with pager (reverse works only for current (first?) page)
    2) The new pager shows 12 images instead of 9. This can break existing sites.

    I have fixed the above issues.

    This issue also has pager issues. If I understand correctly we need to commit another issue first

    Yes, we should merge ✨ Extra configuration options for the Pager Active first. After those changes are merged, we can implement the necessary items_per_page logic for the pagination logic in this issue.

  • πŸ‡§πŸ‡ΎBelarus ivnish

    I merged MR about pager improvements. Do you need to update this MR ?

  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    I merged MR about pager improvements. Do you need to update this MR ?

    Yes, I need to make updates to this MR so that it makes use of the items_per_page parameter. I will submit these changes today.

  • Pipeline finished with Failed
    3 months ago
    Total: 153s
    #561817
  • Pipeline finished with Success
    3 months ago
    Total: 161s
    #561823
  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    I merged MR about pager improvements. Do you need to update this MR ?

    I have made the changes to support the pager improvements. This is ready for your review.

  • πŸ‡§πŸ‡ΎBelarus ivnish

    I left a few comments in MR

  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    Ok, I am working on the changes you have requested.

  • Pipeline finished with Success
    3 months ago
    Total: 189s
    #563634
  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    I have completed the requested changes.

  • Pipeline finished with Canceled
    2 months ago
    Total: 125s
    #565570
  • Pipeline finished with Success
    2 months ago
    Total: 147s
    #565573
  • πŸ‡ΊπŸ‡ΈUnited States circuitcipher

    I wanted to add a quick explanation as to why I made the changes in commit "9b8e3d90 - Fix(entity): Correct target_bundles format for handler_settings"

    I have been working locally on fixing Media Gallery compatibility with Layout Builder and found out that the core logic in Drupal for generating sample content based on bundle types expects that a field's "handler_settings" => "target_bundles" be in a specific format. This fix will be crucial to future enhancements I plan on doing to fix layout builder compatibility.

  • πŸ‡§πŸ‡ΎBelarus ivnish

    Merged! Thanks!

  • πŸ‡§πŸ‡ΎBelarus ivnish
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024