Add support for opening Swiper in a modal window via swiper_formatter settings

Created on 19 August 2024, 3 months ago
Updated 21 September 2024, about 2 months ago

Problem/Motivation

There is a need to enhance the swiper_formatter module to support opening Swiper in a modal window when a teaser (thumbnail) is clicked. This feature would allow users to view Swiper galleries in a more focused way, particularly useful for media content like images, where a full-screen or modal presentation enhances the user experience.
Currently, users can view Swiper galleries directly on the page, but in certain use cases, particularly in media-heavy sites, there is a requirement to display these galleries in a modal window. This would improve the overall user experience by allowing users to interact with the gallery without navigating away from the current page or cluttering the interface with large galleries.

Proposed resolution

  1. Extend swiper_formatter Settings:
    • Add a setting in the swiper_formatter configuration that allows site administrators to choose whether Swiper should open in a modal window when a teaser (thumbnail) is clicked.
    • This setting should include options to enable or disable modal functionality and configure basic modal properties (e.g., modal size, close button visibility, etc.).
  2. Implement Modal Logic:
    • Modify the swiper_formatter rendering logic to include the necessary JavaScript and CSS for handling modals.
    • On teaser click, the Swiper instance should be initialized within a modal. The modal should open, and the Swiper should start at the clicked slide's index.
    • Ensure that the modal remains responsive and fully accessible, supporting keyboard navigation and screen readers.
    • Add support for correctly positioning the Swiper to the clicked slide based on the data-swiper-slide-entity-id attribute, ensuring a smooth user experience.
  3. Use Case:
    • This enhancement is particularly valuable for sites that use Swiper galleries for media content. For example, clicking on an image thumbnail in a gallery list opens a full-screen or large modal displaying the Swiper slider, starting from the selected image.
    • Example scenario: A news website where each article includes a gallery of related images. Clicking on any image opens the full gallery in a modal, allowing readers to view all related images in one place without leaving the article.

User interface changes

  • Enhances the user experience by providing a more immersive viewing option.
  • Offers more flexibility in how Swiper galleries are displayed, catering to different site design needs.
  • Improves content management for editors, allowing them to define how media galleries are presented to users.

New swiper formatter

New settings

✨ Feature request
Status

Needs review

Version

2.0

Component

User interface

Created by

πŸ‡¨πŸ‡¦Canada man-1982

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

Merge Requests

Comments & Activities

  • Issue created by @man-1982
  • Merge request !8Issue #3469036 β†’ (Closed) created by man-1982
  • πŸ‡¨πŸ‡¦Canada man-1982

    man-1982 β†’ changed the visibility of the branch 3469036-add-support-for to hidden.

  • πŸ‡¨πŸ‡¦Canada man-1982

    man-1982 β†’ changed the visibility of the branch 3469036-add-support-for to active.

  • πŸ‡¨πŸ‡¦Canada man-1982

    As proof of works please consider this gif-video

    There is now an option to select another format for the swiper field.

    The result of the work is the ability to open a Swiper by clicking on the content teaser, and the swiper will open in a Drupal modal window on the exact slider where the click occurred.

    Added cashing base on a tags.

    Thank you

  • Status changed to Needs review about 2 months ago
  • πŸ‡¨πŸ‡¦Canada man-1982

    Added a few more images:
    1:

    2:

    3:

  • πŸ‡¨πŸ‡¦Canada man-1982

    What's been added:

    Drupal modal dialog or native HTML5 dialog option
    Controller and route for generating the original Swiper

    • nk_ β†’ committed a7a3fd96 on 1.0.x
      New Dialog feature #3469036; A complete code refactor and  and a couple...
  • πŸ‡³πŸ‡±Netherlands nk_

    Thanks again Andrii for your commitment, it is very appreciated. However the code for 1.0.x version was quite outdated so thanks to motivation gained from you and the other folks I went into a sprint mode and completely re-wrote the code, covering this feature, quite extended with possibilities in comparison with your initial idea as well as some other pending issues here. In shortest this is what is new

    Dialog feature.

    Please see screenshots below.

    • There is total 3 new field formatters for Dialog feature:
      • Swiper entity Dialog - can popup own entity with selected mode (which again can be swiper but in modal), or referenced entity with its mode selected, or a rendered field or rendered field item (e.g. only field item with delta=0) for both entities, own or referenced.
      • Swiper images Dialog - can popup own entity (if the same view mode it'd be swiper in dialog) or just an image with Entity field item selected as Dialog content.
      • Swiper markup Dialog - same like images.
    • Dialog can be one of 4 Drupal ui dialog types:
      • Modal
      • Dialog
      • Dialog off canvas
      • Dialog off canvas top
    • 3. There is quite some Dialog options provided, configurable, such as width, height, ui classes etc.
    • 4. Tokens implementations. Can be used for dialog title and/or custom link on plain images formatter.
    • 5. Pure drupal dialog implementation without additional JS.

    Other improvements

    For now, this is only 1.0.x dev version, 2.0.x version is yet to come, it shall include these and a few more features developed there in the meantime. Testing and feedbacks are very appreciated and I am thankful in advance! Next week I am going to be occupied a lot with the other things but will keep an eye on this one. hoping to have it confirmed by crowd and packed into next 1.0.x release.

    .
    .
    .

  • πŸ‡³πŸ‡±Netherlands nk_
  • πŸ‡³πŸ‡±Netherlands nk_
    • nk_ β†’ committed a7a3fd96 on 2.0.x
      New Dialog feature #3469036; A complete code refactor and  and a couple...
  • πŸ‡³πŸ‡±Netherlands nk_

    Merged and pushed into 2.0.x-dev just now, so changing the version here too.

  • πŸ‡¨πŸ‡¦Canada man-1982

    Hi!
    New features looks really cool and promises.
    going to test lates dev version.
    thanks

  • πŸ‡³πŸ‡±Netherlands nk_

    @man-1982 Thank you, your initiative and code was crucial to have this moving on. As you are aware, the module was needing some sort of general redo and a new version, for quite some time, so ultimately your code wasn't matching with a new structure which does not make it less appreciated or useful.

    Heads up to everyone following - I just pushed a new versions with a couple of relative important fixes. According to config_inspector β†’ there are still some issues with schema, details, but these, so far, do not break anything and shall be fixed before the release.

    @bbu23 thanks so much for hopping in here and for the precise work you do with code!

  • πŸ‡·πŸ‡΄Romania bbu23

    @man-1982 Agree with @nk_, thanks for the contribution and involvement!
    Please let us know if you find anything in your tests, I'm also in the process of testing/reviewing.

  • πŸ‡¨πŸ‡¦Canada man-1982

    @nk_, @bbu23 Thank you for your work

    Close this ticked by know.

    We need to focus on testing the new module's features.

  • πŸ‡·πŸ‡΄Romania bbu23

    We'll keep the ticket open as it's related functionality is being worked on & reviewed. We will close this when a new release is being made.

  • πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

    [OK Drupal.org issue queues, I'll retype this yet again! (always copy what you type here before saving or previewing)]

    I too can confirm that the latest 2.0.x-dev works great for the site this is on. It took some time to get the view mode configured correctly since I only wanted to show one image in the pop - see screenshot.

    Thanks for all the work here guys!

  • πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR
  • πŸ‡³πŸ‡±Netherlands nk_

    @jcl324 I am sorry, I am not managing to catch up on this one but soonest.

    @bbu23 In case you have a chance, we'd just need to test situation where:

    There is Swiper images/dialog formatter on the image field that is attached to Taxonomy term entity. That image field shall have both Title and Alt field enabled, some values for it entered on example terms entity testing items.

    A bug to confirm - there is no option to select Title or Alt field as a Caption on the formatter settings.

  • πŸ‡·πŸ‡΄Romania bbu23

    @nk_ I'm not quite sure what the test is. I did the following in Drupal 10 (because vanilla Drupal 11 is not ready for this yet):

    - I created a taxonomy vocabulary with an image field with ALT and TITLE enabled
    - I configured the display to first show "Swiper images", later "Swiper images Dialog"
    - I added a two terms with each 2 or more images

    The behaviour was ok for images on the term page, but for dialog if I closed the dialog and reopened it, it was empty.

    Later I added a term reference field to a node.
    I tested the following scenarios:
    - Term reference -> non-swiper rendering, so showing the swiper from term through node
    - Term reference with swiper formatter: here, of course a case that probably should not be used, the slider had two arrows each side, so 4 arrows in total, and the behaviour was mixed.

    In none of the cases I could not do anything with the title or alt fields.

  • πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

    @bbu23, just to help clarify here, when you configure the "Swiper images Dialog", do you actually see the setting for "Caption source field"? for me, this doesn't even display so I can't select any option. You can see this on #24, first screenshot.

  • πŸ‡·πŸ‡΄Romania bbu23

    @jcl324 I skipped that point because that is confirmed by @nk_:

    A bug to confirm - there is no option to select Title or Alt field as a Caption on the formatter settings.

    But I confirm that I don't see those options either.

  • πŸ‡³πŸ‡±Netherlands nk_

    Ok, so here's the tiny patch that shall do it. Whoever is able - please do test on entities other than Taxonomy term, thanks!

    @bbu23 I see you are busy with some code, please include this patch once it is convenient for you, cheers.

    • bbu23 β†’ committed ef395b72 on 2.0.x
      Issue #3469036 by nk_: Apply patch from #29 for caption field in...
  • πŸ‡·πŸ‡΄Romania bbu23

    Thanks @nk_, I applied the patch in dev version.

    @jcl324 could you please check again on the latest dev version? Note that there might be newer commits as well, so please make sure to run drush updb when you update to latest dev version. Thanks

  • πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

    Thanks guys, both the patch itself worked as well as the latest dev version. Time to wrap this all up in my branch and get it in front of the client to see. Woot!

  • πŸ‡·πŸ‡΄Romania bbu23

    @jcl324 that's great! Thanks for checking and confirming!

Production build 0.71.5 2024