I try to create view with custom markers for each node depending on taxomomy term.
My steps:
1) Create vocabulary with several terms.
2) Add to each term an image field with icon.
3) Create an leaflet map view with relation to taxonomy terms in this vocabulary.
4) Add geofield and node title fields to view.
5) Add taxonomy term image field to view.
6) In map settings choose "DivIcon" and choose my taxonomy term image field.

But when I try to see my view, I get an error:

Notice: Undefined index: entity in function leaflet_apply_map_settings() (line 394 in file /home/oldsaratov/www/sites/all/modules/leaflet/leaflet.formatters.inc).
EntityMalformedException: Missing bundle property on entity of type node. in function entity_extract_ids() (line 7721 in file /home/oldsaratov/www/includes/common.inc).
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gcb’s picture

Assigned: Unassigned » gcb
Status: Active » Postponed (maintainer needs more info)

Sounds like you might be working with a Dev release: I introduced this bug in commit 1209cfd and fixed it in 3bacba3 -- separated by 2 days. Can you pull down the latest version and let me know if that fixes it?

okolobaxa’s picture

Yes, I use Dev release. I got latest snapshot from http://drupalcode.org/project/leaflet.git but error is still exist.

derhasi’s picture

Status: Postponed (maintainer needs more info) » Active

The problem is, that the fix was only valid for field formatters, not for data provided by views. There the entity is missing in some cases. I'm currently having alook into that code and maybe can provide a patch in some minutes.

derhasi’s picture

The problem was introduced by #2143261: Formatter ignored when Point Icon Marker Field: Image, as that patch assumes, there is allways an image field to render, and that is simply not the case.

derhasi’s picture

Assigned: gcb » derhasi
Status: Active » Needs review
FileSize
1.66 KB

The attached patch should solve the concrete problem. In some cases (when no name field was given), there was simply no entity provided to the point data, so leaflet_apply_map_settings() could not process it.

okolobaxa’s picture

same error after applying this patch and clearing cache

derhasi’s picture

okolobaxa , have you set the description field to entity, like in http://share.undpaul.de/bilder/zeb_Locations_Content__zeb_20140123_16475... ?

okolobaxa’s picture

I set content body as description field. Is it right?

derhasi’s picture

With the current implementation you have to select "<... entity>", so the approach can work. I'm currently working a fix.

kodein’s picture

I have the same problem, when i add my icons from taxonomy term file field i get error:

Notice: Undefined index: entity в функции leaflet_apply_map_settings() (строка 400 в файле /home/.sites/106/site51/web/sites/all/modules/leaflet-dev/leaflet.formatters.inc).

And map does not show, it is all grey. When i change POINT ICON settings to "Icon Source->Icon File" it works.

derhasi’s picture

I've got a new patch, containing some more changes in the options, to better distinguish between icon, "divIcon from field" and "divIcon from markup". What's currently missing, is implementing the replacement patterns of the views rows.

derhasi’s picture

Damn, sorry, the file was missing ...

okolobaxa’s picture

Thanks! This patch partially works for me. No error from first post, but several new problems:

1) Settings for icon field doesn't saves (try in Views).
2) A lot of warrnings on page (one per icon) with text
"Notice: Undefined variable: settings в функции leaflet_apply_map_settings() (line 457 in file /home/oldsaratov/www/sites/all/modules/leaflet/leaflet.formatters.inc)."

derhasi’s picture

Ok, I try to work out some working solution tomorrow. In addition, we should provide some (unit) tests for expected behaviour.

derhasi’s picture

FileSize
1.21 KB
15.69 KB

There is a new patch that will provide an entity for replacement, even if now entity display ways requested.

okolobaxa’s picture

I got this error after applying patch

Fatal error: Cannot access empty property in /home/oldsaratov/www/modules/field/field.attach.inc on line 324

Maybe I applied the patch to the wrong release? I applied to stable release.

derhasi’s picture

FileSize
16.5 KB
0 bytes

A small fix on the previous patch, to store the settings properly.

@okolobaxa there are several problems with the current approach as it tries to use fields from views but does use views from the entity.

derhasi’s picture

FileSize
978 bytes
16.81 KB

Another small additional change, so divIcons can be changed in width and height via css.

I uploaded all changes to a branch on github: https://github.com/derhasi/leaflet/tree/2178231-entity

menelai’s picture

Branch does not work for me.
For example the field in related taxonomy is called "field_marker_1".
The function that renders it will be $icon_field = field_view_field('node', $entity, 'field_marker_1', $icon_config); but there is no such field in $entity and $icon_field is always an empty array.
Also when I save options the "Marker field" option is always set to --none--.

xamanu’s picture

FileSize
8.56 KB

Here is another patch with a different approach than the one from derhasi.

I just propose to render the icon through the regular image theming function instead of the "whole" field rendering process. As mentioned in #3 by derhase, the field is not always the same entity as the main view element, like it is the case in the beginning: the view's main entity is a node, but the image field comes from a taxonomy term. Anyway it is easy to get the image information out and render it properly, so why not keeping things simple!?

Further, I reduced the selection options in the leaflet's views style settings to allow image fields only for the use as DivIcon. This makes it easier for the user. And during the process of understanding the code, I tried to improve some code documentation.

timodwhit’s picture

Since leaflet_apply_map_settings() requires the entity, I wrote a simple patch, that checks if the if the icon is html and then returns the entity if not already returned.

FWIW: I don't think we should have to load the entity for this, but this plays nicely until a larger solution like that in #19 is around.

timodwhit’s picture

FileSize
942 bytes

Forgot to check if iconType was set.

timodwhit’s picture

FileSize
1.22 KB

Well this is embarassing... checked the wrong way.

Anonymous’s picture

This patch is based on xamanu's #20, but bypass the theme() <img> generation which is now written inline. This allows to use term fields images in files/ folder instead of the theme folder.

Anonymous’s picture

Fix my previous patch: a variable initialization was missing.

omers’s picture

Status: Needs review » Reviewed & tested by the community

patch on #25 works fine from this side Thanks @Peuc

Rhodungeon’s picture

Patch #25 is working for me too. Any idea about committing it?