The 3 icons at the top of the page

Hi Guys

I want to change the 3 icons at the top of the page to words , And i cant seem to find out how to get at them , would someone please help me .

 

Thanks

  • 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,
            ));
        }
    }
  • Hi iionly

    Im missing something here , the friends icon stays an icon and i cant see why , Will you please re look at it for me ?

     

    Thanks

     

  • 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.