diff options
Diffstat (limited to 'engine/lib/views.php')
-rw-r--r-- | engine/lib/views.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/engine/lib/views.php b/engine/lib/views.php index e20c98929..56325ebda 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -774,6 +774,47 @@ function elgg_view_entity(ElggEntity $entity, $full = false, $bypass = true, $de } /** + * View the icon of an entity + * + * Entity views are determined by having a view named after the entity $type/$subtype. + * Entities that do not have a defined icon/$type/$subtype view will fall back to using + * the icon/$type/default view. + * + * @param ElggEntity $entity The entity to display + * @param string $string The size: tiny, small, medium, large + * @param array $vars An array of variables to pass to the view + * + * @return string HTML to display or false + */ +function elgg_view_entity_icon(ElggEntity $entity, $size = 'medium', $vars = array()) { + + // No point continuing if entity is null + if (!$entity || !($entity instanceof ElggEntity)) { + return false; + } + + $vars['entity'] = $entity; + $vars['size'] = $size; + + $entity_type = $entity->getType(); + + $subtype = $entity->getSubtype(); + if (empty($subtype)) { + $subtype = 'default'; + } + + $contents = ''; + if (elgg_view_exists("icon/$entity_type/$subtype")) { + $contents = elgg_view("icon/$entity_type/$subtype", $vars); + } + if (empty($contents)) { + $contents = elgg_view("icon/$entity_type/default", $vars); + } + + return $contents; +} + +/** * Returns a string of a rendered annotation. * * Annotation views are expected to be in annotation/$annotation_name. |