Skip to content

Commit 54359e0

Browse files
authored
Issue #74: Fix entity rendering with entity types other than node in leaflet_views (#75)
1 parent 9bd693d commit 54359e0

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

modules/leaflet_views/leaflet_views_plugin_style.inc

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@ class leaflet_views_plugin_style extends views_plugin_style {
1616
public function init(&$view, &$display, $options = NULL) {
1717
parent::init($view, $display, $options);
1818
$this->entity_type = $this->options['entity_type'];
19-
$this->entity_info = entity_get_info($this->entity_type);
19+
if (!empty($this->entity_type)) {
20+
$this->entity_info = entity_get_info($this->entity_type);
21+
}
2022
// Fallback for views that do not have entity_type set, for example
21-
// because the view was created before this option got introduced.
22-
if (empty($this->entity_type)) {
23-
$info = entity_get_info($view->base_table);
24-
if (!empty($info)) {
25-
$this->entity_type = $view->base_table;
26-
$this->entity_info = $info;
23+
// when switching from different style plugins.
24+
else {
25+
$all_entity_info = entity_get_info();
26+
$derived_entity_type = FALSE;
27+
foreach ($all_entity_info as $entity_type => $definition) {
28+
if ($definition['base table'] == $view->base_table) {
29+
$derived_entity_type = $entity_type;
30+
break;
31+
}
32+
}
33+
if ($derived_entity_type) {
34+
$this->entity_info = $all_entity_info[$derived_entity_type];
35+
}
36+
else {
37+
$this->entity_info = array('view modes' => array());
2738
}
2839
}
2940
}
@@ -319,7 +330,7 @@ class leaflet_views_plugin_style extends views_plugin_style {
319330
$entities = entity_load($this->entity_type, array($entity_id));
320331
$entity = $entities[$entity_id];
321332
if ($this->options['description_field'] === '#rendered_entity') {
322-
$build = node_view($entity, $this->options['view_mode']);
333+
$build = entity_view($entity, $this->options['view_mode']);
323334
$description = backdrop_render($build);
324335
}
325336
// Normal rendering via fields:

0 commit comments

Comments
 (0)