Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently in the Views Display, you can only choose a field to be displayed as the "description" which can be used as the body of popup. There should be another option to render out the fields like in a normal view. This is currently a feature in the 1.x branch. I think it is very useful if you want to just include a few fields, as well as being able to leverage more Views theming.
Comments
Comment #1
zzolo CreditAttribution: zzolo commentedComment #2
tmcw CreditAttribution: tmcw commentedGiven that this is now a theme function, I don't think that this is necessary. Do you?
Comment #3
zzolo CreditAttribution: zzolo commentedI would say its still open. The theme function is for the grouping, which renders a bunch of outputs together in the same popup or tooltip.
The need here is for our plugin to render the fields of a view like it normally would. For instance, if you wanted to have a title and an image in the popup, this is not currently possible without some sort of composite field. This should just be a matter of porting this functionality from 1.x. I plan on using my sprinting time next week at DrupalCon towards OpenLayers (with phayes), so I should be able to address this (and more) this weekend and next week.
Comment #4
kdebaas CreditAttribution: kdebaas commentedPending this functionality, how would I go about theming the popup content? Where should I start looking?
Thanks!
Comment #5
zzolo CreditAttribution: zzolo commentedI looked into this one a few days ago and ran into a bit of a stumbling point because the views display plugin is not using row plugins (actually the style plugin needs to be designated) and after about an hour of trying to make work, I out it off. It seems fairly straightforward of changing the switch to TRUE but for some reason that was not fully working for me. I'll have to put more time into it.
As far as theming, in theory, you should be able to use the regular views themeing functions.
Comment #6
kdebaas CreditAttribution: kdebaas commentedIt looks like I can't theme the field that is used for "description" in the popup with a views-view-field.tpl.php file, as openlayers is using a raw value from the views row. Is there any other way/approach?
Thanks.
[Edit]: views-view-field.tpl.php instead of views-view.tpl.php
Comment #7
zzolo CreditAttribution: zzolo commentedI thought you were referring to this ticket and the changes that will be made here.
If you want to theme the current output, you can use:
For non-grouped data, you should be able to theme the field
For grouped data, there is currently an issue: #736576: Use theme function instead of hard-coded markup in grouped Views display plugin
Comment #8
kdebaas CreditAttribution: kdebaas commentedSorry, you are right, I should have opened a new issue: #787026: Allow non-grouped views output to be themed with Views
Comment #9
davidhk CreditAttribution: davidhk commentedI have this working so that the contents of the popup comes from the views rows plugin, but I need some help on how to fit it in with the current design.
Currently there's no way for the admin to choose which row plugin he wants to use. The problem is that the display plugin and style plugin both have
So when views builds its list of row plugins to choose from, it looks for plugins with a type of 'openlayers', and of course there aren't any. The ones we are most likely to use (Fields, Node) have type 'normal'.
There are a couple of workarounds I can think of, but neither are very user-friendly:
- fix the default row plugin to be 'fields'. The user can configure its settings, they just can't change to another row plugin.
- Use the Default display to change the row plugin, which will then change it for the OpenLayers Data display
An alternative is to change the type of the display and style to 'normal'. That would give the admin access to more row plugins, and give the admin a more typical views experience. The downside is that the Openlayers Data style plugin would then be available to all displays, whereas currently it only shows up if you're editing an OpenLayers Data display.
What do the module developers recommend?
Comment #10
EmanueleQuinto CreditAttribution: EmanueleQuinto commentedJust a side note: even if the rendering is completely handled by the plugin itself the fields are processed and themed as usual.
You can test this by commenting (disclaimer: dirty trick here)
unset($options['analyze-theme']);
at the end of openlayers_views_plugin_display_openlayers.incThen you will see the available templates in the view UI; if you pick and change the field template adding a
dpm($field)
(ordsm($output)
if you don't have enough memory) you'll notice that the template is called as usual.Moreover if you replace the line where the feature item is set (around line 360 in openlayers_views_style_data.inc)
you'll be able to use the themed value (given that you modify the appropriate template field file).
+1 for the first option suggested by gwulo (fix the default row plugin to be 'fields').
Comment #11
davidhk CreditAttribution: davidhk commentedThanks Emanuele. I'm still finding my way around Views, so your comments are very helpful.
I'll post up the changes as a patch later this week, and will be grateful for your feedback.
Regards, David
Comment #12
milesw CreditAttribution: milesw commentedI've been hunting around for this exact functionality. Which theme function are you guys referring to here?
(apologies, I know this doesn't relate to the issue topic)
Comment #13
davidhk CreditAttribution: davidhk commentedHere's the patch. It's a little different from the issue title - it uses the views row to build the full contents of the popup, not just the description.
To see a demo, try http://gwulo.com/OL_demo. The view has fields title, lat, lon, and two dates. The lat & lon are excluded from display. The dates are set to display inline with ' - ' as separator. So the popup is built just using standard views functionality.
After installing the patch, existing views and popups continue to work as before. BUT, the OpenLayers Data display shows an error "Row Style: Missing Style Plugin", and doesn't get any of the new functionality from this patch. The only way I can see around this is to edit the view to remove then re-create the OpenLayers Data display.
When you create a new OpenLayers Data display, there's a new option on the OpenLayers Data style plugin. It lets the views admin choose whether the popup content is built from Title & Description (ie the current way), or from the Views row.
The popup's content is all built in the view now, so the javascript behaviour just displays whatever it is given, without any changes or additions.
Comment #14
zzolo CreditAttribution: zzolo commentedHi @gwulo, thanks for the patch(es). I am still trying to catch up on emails and tasks, but hopefully will have time to review this soon. I am really interested in getting this in as it is a much needed function that was not ported from 1.x. What's with the multiple patches by the way?
Comment #15
davidhk CreditAttribution: davidhk commentedI used Winmerge to make the patches - it makes one patch file for every two files I compare.
Is there a better way - eg should I cut & paste them into one file?
This isn't my day job, so lots to learn!
Comment #16
zzolo CreditAttribution: zzolo commentedThis should be helpful: http://drupal.org/patch/create
Comment #17
davidhk CreditAttribution: davidhk commentedHere's the patch again, with the changes in a single file.
Comment #18
toomanypets CreditAttribution: toomanypets commentedSubscribe.
Comment #19
zzolo CreditAttribution: zzolo commented@gwulo, thanks for the patch and sorry for the delay in response. Basic look at patch seems ok. The one thing I would suggest is not to do the option of choosing between fields and rows, but to just have drop down for description to have an option. Will test soon.
Comment #20
davidhk CreditAttribution: davidhk commentedAn option in the description drop-down would work too. I'm off on summer vacation for a couple of weeks, but will have a look at it when I get back - if noone beats me to it!
Regards, David
Comment #21
BWPanda CreditAttribution: BWPanda commentedPatch applies, but doesn't seem to be working - I can see the new setting for displaying the view row in the popup, but when I select it and save, the map popups are empty...
Comment #22
davidhk CreditAttribution: davidhk commented@BWPanda, sorry to hear that. The only things I can suggest you've probably tried already - clear the browser cache and drupal cache, and make sure that in views there are some fields selected for display.
I'll have some time next week to make the change suggested in #19, and will test the current patch against the latest dev build then.
Comment #23
BWPanda CreditAttribution: BWPanda commentedIf I dsm() the value of
$feature['attributes']['popup_content']
at the end of the patch in the if() statement, I get the following:So it can see each of the fields, just not the values in them...
And it was working when I just assigned one field to the title and description before I applied your patch, so the view is setup correctly.
Another thing to note, I just tried changing 'In popup, show:' to 'Title and Description', but the popups are still empty and my dsm() output from above still shows (which is only present in the 'if' part, not the 'else' part)...
Comment #24
davidhk CreditAttribution: davidhk commented@zzolo, here's the revised patch based on your comment in #19. It's a smaller change than the previous one, so thanks for the suggestion.
@BWPanda, I'm not sure what's causing the problem. It's not a big change to the code, and just uses the standard Views row rendering to build the content.
I'd certainly recommend trying a new view to see if that makes any difference. The steps I followed were to first build as simple a view as possible. Just add filters, and fields to display. At that point the Live Preview should show the fields for 10 records. Check that each record shows something! (In testing I confused myself at one point where I had some old records with no data in the fields I used for popups, and couldn't understand why I had blank pop-ups).
Then add & configure the OpenLayers Data and OpenLayers Map. On the OpenLayers Data config screen, choose Style Options and set 'Description Field:' to . You should get a map with 10 markers, and each pop-up shows the same information that was displayed in the Live Preview for its record.
Comment #25
davidhk CreditAttribution: davidhk commentedTry again, with correct filename: 748646-24.patch
Comment #26
BWPanda CreditAttribution: BWPanda commentedI'd love to mark this as RTBC, but it's still not working for me...
I installed a brand new copy of OL 2.x-dev on my test site, applied the patch, then created some nodes with location data and a view to match.
When setting a single field to either the title or description (or both), the popups display correctly. But when I set the description to
'<all> (render entire row)'
, nothing's displayed in the popup (unless of course I've also set a title, which displays but not the description).Comment #27
BWPanda CreditAttribution: BWPanda commentedAs far as I can tell, it seems the issue lies with
$this->row_plugin->render($record)
. As above, it outputs the HTML, but without any values in it... I've looked through the code to see if I could work out what it should be instead, but I don't know enough about Views to figure it out.Comment #28
davidhk CreditAttribution: davidhk commented@BWPanda, if you : edit your view, click the 'OpenLayers Data' tab, then click the 'Preview' button at the bottom of the screen, do you see all the fields displayed as you expect to find them in the pop-up?
If you look at the attachment Views-preview.jpg, you can see how it looks here. Then popup.jpg shows how the same fields appear in the popup.
If that doesn't help, I'm not sure what to try next. It would help if someone else could also try the patch, to get another data point.
Comment #29
BWPanda CreditAttribution: BWPanda commentedgwulo, you can't preview map data, as you get the message: "OpenLayers views are not compatible with live preview" when you try... That's all I see when I preview my map view (both the data display and the page display).
Comment #30
davidhk CreditAttribution: davidhk commentedMy mistake, I was forgetting about the little drop-down to the left of the preview button.
So the Views-preview.jpg on #28 is for my "Defaults" display. What do you see if you preview the Defaults display?
A bit more background in case we use different steps to build our views. On my test View I've got three displays listed:
- Defaults
- OpenLayers Data
- Page (which is really the OpenLayers map)
Both Defaults and OpenLayers Data show "Row Style: Fields", and all the fields in the "OpenLayers Data" display show "Status: using default values.".
So as I understand it whatever shows up on the "Defaults" display's preview should be what Views generates when we call render to build the content for the popup.
Comment #31
BWPanda CreditAttribution: BWPanda commentedLet's go one better: attached is an export of my map view.
My Defaults display preview shows the same message as my OpenLayers Data one (because I setup the OpenLayers Data display without overriding default values), but I also have an Attachment display setup to show the same info as the OpenLayers Data one for testing purposes - it shows the following on preview:
Hope that helps figure this out.
Comment #32
davidhk CreditAttribution: davidhk commentedI've built a view the way you described, but the pop-ups still display their contents ok (export attached).
I notice I'm running an old version of views, 2.6. Which version are you using?
Otherwise, these are the only differences I can see between our exports:
Defaults
- Fields: GL uses Latitude / Longitude / Title. BWP uses WKT / Title / Body
- Items per page: GL use default 10. BWP set to 0
OpenLayers Data
- Data Source: GL uses lat/lon, BWP uses WKT
Page
- Attachment display: GL doesn't use, BWP uses
- Menus: GL doesn't use, BWP defines a menu item
Comment #33
markabur CreditAttribution: markabur commentedI haven't tested the patch but the 1-line change in #10 is exactly what I was looking for. It allows for a tpl file and corresponding preprocess function to affect the description field before it goes into the popup. In my case I was needing to load the rendered node teaser into the popup and this is the only way I've found to do it in OL 2.x.
Comment #34
zzolo CreditAttribution: zzolo commented#25: 748646-24.patch queued for re-testing.
Comment #36
zzolo CreditAttribution: zzolo commentedGetting there, I think. I ran in the following problem:
So, basically, the display now can use row plugins but none have been defined to work with it? So, there are no row plugins to pick from.
Also, upgrade path needs to be thoroughly tested here, as I have feeling this will cause soem problems in Views.
Comment #37
davidhk CreditAttribution: davidhk commentedThanks for taking a look at this.
There are definitely problems with an upgrade path. See notes in #13:
---
After installing the patch, existing views and popups continue to work as before. BUT, the OpenLayers Data display shows an error "Row Style: Missing Style Plugin", and doesn't get any of the new functionality from this patch. The only way I can see around this is to edit the view to remove then re-create the OpenLayers Data display.
---
I don't know if there's any better way around this.
See also the notes in #9.
Comment #38
YK85 CreditAttribution: YK85 commentedsubscribing
Comment #39
JoshuaBud CreditAttribution: JoshuaBud commented#25: 748646-24.patch queued for re-testing.
Comment #40
EgonO CreditAttribution: EgonO commented+1 Subscribe
Comment #41
ollynevard CreditAttribution: ollynevard commentedPatch #25 didn't work for me. Nothing gets rendered in the popup description.
The views row index (
$this->view->row_index
) never gets set for non-grouped displays so when$this->row_plugin->render($record)
gets called views doesn't know which row to render.I've re-rolled the patch from #25 against 6.x-2.x with a fix for setting the row index. Now openlayers views will correctly render all fields in the popup description when
<all> (render entire row)
is selected for the description in the style options.I've not submitted a patch to Drupal before as someone else has always beaten me to it. I followed the instructions here, hopefully it is correct?
Comment #42
mansspams CreditAttribution: mansspams commentedlistening
Comment #43
portulacaI tried the #41 patch and I can see the option in views but I'm getting this error after I update the field and after saving the views:
Style OpenLayers Data requires a row style but the row plugin is invalid.
The popups don't include any additional fields.
Comment #44
bsandor CreditAttribution: bsandor commentedsubscribing
Comment #45
zzolo CreditAttribution: zzolo commentedPatches for 6.x welcome, but any development will be focused on D7.
Comment #46
brunorios1 CreditAttribution: brunorios1 commentedsubscribing
Comment #47
fragje CreditAttribution: fragje commentedsubscribing
Comment #48
pbuyle CreditAttribution: pbuyle commentedHere is a re-roll of the patch in #41 for the 7.x-2.x branch. I changed
#all_fields
to#row
, it made more senses to me. I've also added an exception inopenlayers_views_style_data::map_features
to keep fields excluded from display as map features when they are used as data source fields. This allow, for instance, the title, latitude and longitude fields to be used as data source but not rendered in the description.Comment #49
pbuyle CreditAttribution: pbuyle commentedComment #50
zzolo CreditAttribution: zzolo commentedThanks for everyone's work on this. Committed:
http://drupalcode.org/project/openlayers.git/commit/effadd4
Comment #51
nyleve101 CreditAttribution: nyleve101 commentedHi,
Just wondering if this will be backported to 6.x-2.x?
Thanks,
Eve
Comment #52
zzolo CreditAttribution: zzolo commentedHi @nyleve101. I would love to, but my time is pretty limited these days, and I am pretty much the only one working on this project at the moment. Patches are welcome.
Comment #53
jvizcarrondo CreditAttribution: jvizcarrondo commentedI have developed a solution to enable all field as row style in views, new module allows you to hide fields and all operations fields on row style in views (in this case, display openlayers data). This work was done on the openlayers version 6.x-2.0-beta1 (I am including the patch) by request of Evelyn (@nyleve101) and is now working satisfactorily. I hope it helps for someone, can be improved or to be included in a future.
Juan
Comment #54
zzolo CreditAttribution: zzolo commentedThanks @jvizcarrondo. Can @nyleve10 or someone else confirm that this works.
Comment #55
nyleve101 CreditAttribution: nyleve101 commentedYup, it works perfectly!
Comment #56
PolIs it possible to have a reroll of this patch ?
Comment #58
ken-g CreditAttribution: ken-g as a volunteer and commented