Create a plugin with the following in the init function:
elgg_unregister_plugin_hook_handler('register', 'menu:topbar', 'messages_register_topbar');
elgg_register_plugin_hook_handler('register', 'menu:topbar', 'my_messages_register_topbar');
elgg_unregister_event_handler('pagesetup', 'system', 'profile_pagesetup');
elgg_register_event_handler('pagesetup', 'system', 'my_profile_pagesetup', 50);
elgg_unregister_event_handler('pagesetup', 'system', '_elgg_friends_page_setup');
elgg_register_event_handler('pagesetup', 'system', 'my_elgg_friends_page_setup');
This unregisters the Elgg core functions that register the topbar menu items and then you register your own versions of these funtions that you can modify to use text instead of icons.
Apart from the lines above in the init functions you also need to add the following functions used. I've modified the code originally in Elgg core to use text instead of icons. If you provide the menu item text strings in a language file in your plugin it gets more flexible, i.e. you could use different texts for different languages. In this case you would need to use elgg_echo() to fetch the strings (I've added the alternative commented out below in the functions).
function my_messages_register_topbar($hook, $type, $items, $params) {
if (!elgg_is_logged_in()) {
return;
}
// original topbar entry with icon
// $text = elgg_view_icon("mail");
// text instead of icon
$text = "Messages";
// or you could use elgg_echo to allow for translation of text
// then you need a language file (at least en.php) that provides
// "my_plugin_name:message_item_text" => "Messages"
// $text = elgg_echo("my_plugin_name:message_item_text");
$tooltip = elgg_echo("messages");
// get unread messages
$num_messages = (int)messages_count_unread();
if ($num_messages != 0) {
$text .= "<span class=\"messages-new\">$num_messages</span>";
$tooltip .= " (" . elgg_echo("messages:unreadcount", array($num_messages)) . ")";
}
$items[] = ElggMenuItem::factory([
'name' => 'messages',
'href' => 'messages/inbox/' . elgg_get_logged_in_user_entity()->username,
'text' => $text,
'priority' => 600,
'title' => $tooltip,
]);
return $items;
}
function my_profile_pagesetup() {
$viewer = elgg_get_logged_in_user_entity();
if (!$viewer) {
return;
}
$text = "Profile";
// or with elgg_echo
// $text = elgg_echo("my_plugin_name:profile_item_text");
elgg_register_menu_item('topbar', array(
'name' => 'profile',
'href' => $viewer->getURL(),
'text' => $text,
'priority' => 100,
'link_class' => 'elgg-topbar-avatar',
'item_class' => 'elgg-avatar elgg-avatar-topbar',
));
}
function my_elgg_friends_page_setup() {
$owner = elgg_get_page_owner_entity();
$viewer = elgg_get_logged_in_user_entity();
if ($owner) {
$params = array(
'name' => 'friends',
'text' => elgg_echo('friends'),
'href' => 'friends/' . $owner->username,
'contexts' => array('friends')
);
elgg_register_menu_item('page', $params);
$params = array(
'name' => 'friends:of',
'text' => elgg_echo('friends:of'),
'href' => 'friendsof/' . $owner->username,
'contexts' => array('friends')
);
elgg_register_menu_item('page', $params);
}
// topbar
if ($viewer) {
$text = "Friends";
// or with elgg_echo
// $text = elgg_echo("my_plugin_name:friends_item_text");
elgg_register_menu_item('topbar', array(
'name' => 'friends',
'href' => "friends/{$viewer->username}",
'text' => elgg_view_icon('users'),
'title' => elgg_echo('friends'),
'priority' => 300,
));
}
}
Well, with a little bit of thinking you might have found the error yourself. ;-)
I forgot to update the menu registration code from the original code to the code that uses the $text string. So, just change
elgg_register_menu_item('topbar', array(
'name' => 'friends',
'href' => "friends/{$viewer->username}",
'text' => elgg_view_icon('users'),
'title' => elgg_echo('friends'),
'priority' => 300,
));
into
elgg_register_menu_item('topbar', array(
'name' => 'friends',
'href' => "friends/{$viewer->username}",
'text' => $text,
'title' => elgg_echo('friends'),
'priority' => 300,
));
in the my_elgg_friends_page_setup() function.
am I correct i in saying that this system is a oop framework ? what has composer got to do with it ?
, Im looking for a light bulb moment here , but so far Im a bit dim :-)
I created a extra field in the registration page Gender , using profile manager, I now want to set a tiger to forward the user to ether the normal , we have sent you and email , Or a rules page based on gender selection , normal i would add a if then to the registration button , but how would you go about it in elgg as it seems to build these pages on the fly.
Do you mind teaching ? I had a friend that taught me a lot over the years but I have sadly recently lost touch , and cant find out what happend to him
The original purpose of composer is management of dependencies (e.g. 3rd party scripts/libs). The developer doesn't have to fetch all the 3rd party code from different sources and add it to the code (e.g. a plugin) but can define the dependencies and let composer do the job.
For the composer based installation of Elgg to work Elgg itself is defined as a dependency and fetched by composer then. The zip archives of the Elgg releases contain an image of an installation made with composer (simply said) with all the external dependencies already included.
For developing or customizing Elgg and using composer nonetheless you would have to fork Elgg and then pull your forked Elgg version instead. Strictly speaking, you shouldn't modify Elgg core files though but make all customizations by creating a plugin(s). So, you wouldn't necessarily have to fork Elgg itself. You could also put your plugin(s) on github/packagist and then add them in the composer project as dependencies. Then they will get added to an Elgg installation made by composer. Or you could just copy your own or other additional plugins in the mod folder regardless if it's a composer or zip archive made installation of Elgg.
Elgg already has some event handlers that get triggered at specifc situations, e.g. a user logs in (see http://learn.elgg.org/en/stable/guides/events-list.html). Another mechanism are plugin hooks that get triggered by Elgg/plugins at specific points.
The login redirect depending on gender could work with the following code (untested and also the part of the code that checks the gender profile field is not included - you would have to add that on your own depending on the profile field name/type... shouldn't be too complicated):
<?php
elgg_register_event_handler('init','system','gender_login_init');
function gender_login_init() {
elgg_register_event_handler('login:after', 'user', 'gender_login_event_handler', 9999);
}
function gender_login_event_handler($event, $type, $user) {
if (empty($user) || !elgg_instanceof($user, "user")) {
return;
}
elgg_register_plugin_hook_handler("forward", "system", "gender_login_forward_hook");
}
function gender_login_forward_hook($hook_name, $entity_type, $return_value, $params) {
$user = elgg_get_logged_in_user_entity();
if (empty($user)) {
return $return_value;
}
// HERE YOU HAVE TO ADD THE CODE THAT CHECKS THE GENDER OF THE USER AND SETS THE FORWARD FORWARD URL
// AS YOU WANT IT TO BE DEPENDING ON THE GENDER
$return_value = $forward_url;
return $return_value;
}
Im so blown away with the way you know this, i have sat looking at the registration page for ages, if you call the page , and then view source there are no values set for a drop down of male female and yet it gets it 100% into the db.
Thank you so much for your help i will go back and look again with what you have given me ..
Have an awesome day :-)
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.