Render a different View in marker popup

Created on 23 March 2022, over 2 years ago
Updated 27 November 2024, 25 days ago

Putting this out there as a proof of concept if it helps anyone. I don't really expect this to be merged but I could see opportunities for eventually expanding options available in the popup via a plugin system. And if anyone wants to point out a better way to accomplish this I'm all ears!

Problem/Motivation

We had a use case that required rendering a View in a marker popup. The tricky part is the popup View needs to be filtered by the same filters as the main leaflet map. We experimented with using https://www.drupal.org/project/views_field_view to embed the popup View within the main View but this had performance problems. Ideally we wanted to be able to render a View with arbitrary $args via ajax at the time the popup is triggered.

Proposed resolution

Add a popup option to render a particular View display, with https://www.drupal.org/project/views_filterfield and a token-replacing argument string to pass the map View's exposed filters to the popup View.

The major downside here is adding a bunch of extra options to the Leaflet style form. The actual popup functionality is pretty clean and borrows methods from the existing the ajax entity popup controller. If the module wanted to expand on this pattern (e.g., I can see a use case for rendering a popup from an arbitrary controller method) it'd be a good idea to create a plugin system and/or make an interface/base class for the ajax controllers.

Feature request
Status

Active

Version

2.2

Component

Code

Created by

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