How can I go about listing a custom icon alongside an entity in Elgg? With my approach so far, the icon gets uploaded fine, but I'm unable to retrieve it successfully. I only get the default 'Gray Question Mark Icon' to show?
A user uploads an entity while adding an entity object like so (The action file):
This is the form:
<div>
<label><?php echo elgg_echo("bread:icon"); ?></label><br />
<?php echo elgg_view("input/file", array("name" => "icon")); ?>
</div>
<div>
<label for="title"><?= elgg_echo("title"); ?></label><br />
<?= elgg_view('input/text', ['name' => 'title', 'id' => 'title']); ?>
</div>To retrieve the entity, I start with:
Start.php
// Register URL handlers for object
elgg_register_plugin_hook_handler('entity:icon:url', 'rentals', 'bread_type_set_icon_url');
function bread_type_set_icon_url($hook, $type, $url, $params) {
$bread = $params['entity'];
$size = $params['size'];
$icontime = $bread->icontime;
// handle missing metadata (pre 1.7 installations)
if (null === $icontime) {
$file = new ElggFile();
$file->owner_guid = $bread->owner_guid;
$file->setFilename("bread/" . $bread->guid . "large.jpg");
$icontime = $file->exists() ? time() : 0;
create_metadata($bread->guid, 'icontime', $icontime, 'integer', $bread->owner_guid, ACCESS_PUBLIC);
}
if ($icontime) {
// return thumbnail
return "bread_types/$bread->guid/$size/$icontime.jpg";
}
return elgg_get_simplecache_url("bread/default{$size}.gif");
}then, in views/default/resourses/bread.php:
$content = elgg_list_entities(array(
'type' => 'object',
'subtype' => 'bread',
'full_view' => false,
'no_results' => elgg_echo("bread:none"),
'preload_owners' => true,
'preload_containers' => true,
'distinct' => false,
));
$body = elgg_view_layout('content', array(
'filter_context' => 'all',
'content' => $content,
));
echo elgg_view_page($title, $body);
and in views/default/object/bread.php:
$bread = elgg_extract('entity', $vars, FALSE);
$bread_icon = elgg_view_entity_icon($bread, 'small');
$params = array(
'entity' => $bread,
);
$params = $params + $vars;
$list_body = elgg_view('object/elements/summary', $params);
echo elgg_view_image_block($bread_icon, $list_body);info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Nikolai Shcherbin@rivervanrain

Nikolai Shcherbin - 0 likes
- Revilo@Revilo

Revilo - 0 likes
- ura soul@tunist

ura soul - 0 likes
- manfred salomon@lisha

manfred salomon - 0 likes
- manfred salomon@lisha

manfred salomon - 0 likes
You must log in to post replies.I haven't checked but you can try it:
All in start.php
Don't forget about your own icons in folder mod/bread/graphics/icons/ (large.png, medium.png, small.png etc..)
Thanks for the reply RvR, but that didn't change anything.
here's a hook i just wrote in elgg 2.1 to do this:
and here's the call for the hook in start.php of my theme:
Have a look in the groups plugin.
Because the user can upload a group picture the plugin must display it instead of the user image. That is what you want assume.
Look how the group plugin handles the custom image and make it in your plugin the same way.
Look in the start.php of the groups plug in. You find an hook:
elgg_register_plugin_hook_handler('entity:icon:url', 'group', 'groups_set_icon_url');
In the hook is a pagehandler:
elgg_register_page_handler('groupicon', 'groups_icon_handler');
Modify "group" with "bread"
and
copy/paste and modify the functions of the hook and pagehandler point to.
- - - - -
Note:
Don't forget to add to your "bread"-pagehandler:
case 'profile':
// Page owner and context need to be set before elgg_view() is
// called so they'll be available in the [pagesetup, system] event
// that is used for registering items for the sidebar menu.
// @see groups_setup_sidebar_menus()
elgg_push_context('bread_profile');
elgg_set_page_owner_guid($page[1]);
Change the hook NOT to:
elgg_register_plugin_hook_handler('entity:icon:url', 'bread', 'groups_set_icon_url');
change it to:
elgg_register_plugin_hook_handler('entity:icon:url', 'object', 'groups_set_icon_url');
and filter in the function like:
if (elgg_instanceof($breadentity, 'object', 'bread')) {