registering to end of menu_topbar

Looked here and here,

But still unsure how to add so that new menu item is added to back of menu?

by default it adds to the front..

  • Make a directory in your them, and inside that directory, put your image. E.g., if your custom theme/plugin is XY, then it looks like this: mod/XY/directory/image.png (or in whatever format you saved your image). 

    Then do this: 

    elgg_register_event_handler('init', 'system', 'custom_menu');

    function custom_menu() {
    elgg_unregister_menu_item('topbar', 'elgg_logo');

    $site_url = elgg_get_site_url();
    $logo_url = elgg_get_site_url() . "/mod/XY/directory/image.png";

    elgg_register_menu_item('topbar', array(
    'name' => 'elgg_logo',
    'href' => "$site_url",
    'text' => "<img src=\"$logo_url\" alt=\"Elgg logo\" width=\"38\" height=\"20\" />",
    'priority' => 1,
    'link_class' => 'elgg-topbar-logo',
    ));
    }

  • i take it i dont have to call the function after this, thats what the event handler is there for?
    anyhow, this still didnt work for me.... the user profile is still the users image... i put this code in my start.php for my theme and my directory structure is as urs is.

    elgg_register_event_handler('init', 'system', 'custom_menu');

    function custom_menu() {
    elgg_unregister_menu_item('topbar', 'elgg_logo');

    $site_url = elgg_get_site_url();
    $logo_url = elgg_get_site_url() . "/mod/independence/images/pin.png";

    elgg_register_menu_item('topbar', array(
    'name' => 'elgg_logo',
    'href' => $site_url,
    'text' => "<img src=" .$logo_url ." alt=\"Elgg logo\" width=\"38\" height=\"20\" />",
    'priority' => 1,
    'link_class' => 'elgg-topbar-logo',
    ));
    }

    i dont know why its happy to find the sprite image but not my own. my css doesnt seem to be applied, it inherits the sprite one for user icons. where does it say to use that particular sprite? cos i might just use a different one. i will check out that link costa.


  • thanks Asmarino, the plugin works (and obviously makes it easy for me).

    I was just wondering one more thing. If i extend the elgg_sprites.png (and appropriate css) do i just changes the elgg/_graphics/elgg_sprites.png or can i do it modularly as well in a plugin, so that when i upgrade it will come with me. obviously if not, i can just remember to copy over the _graphics folder too..

  • I used to tamper with the core files before, but I learned not to touch it as it can crash upgrading. NOTHING should be touched in the core files.

    Do this: copy the icons.php file in elgg/views/default/css/elements/icons.php and paste it in <your custom theme>/views/default/css/elements (make the following folders in your custom theme: views -> default -> css -> elements). Then edit the pasted icons.php so that it will always be with you when you upgrade.  

     

  • The last sentence should be read: Then edit the pasted icons.php. Make the changes in the plugin so that it will always be with you when you upgrade :). 

  • there you go asmarino, you learn quickly :)

  • yeh yeh i get that. but say i wanted to make a custom icon, for i dunno, say a link to my blog. the icons.php is pointing to the png file in the _graphics. and if i upgrade elgg later, unless i remember to copy that folder over too i would lose it. i guess id have to maybe change where the icons.php is looking for the png file and point it to a plugin folder that will come with me.. but anyhow, its not too hard for me to remember to copy over that folder, and besides ive decided to use icons already in the core sprite.

    two other question however (you's have been very helpful btw thanks alot)

    1) i have unregistered all my menu links except i cant seem to find the label to
    unregister that link created by izap videos plugin.

        elgg_unregister_menu_item('site', 'activity');
        elgg_unregister_menu_item('site', 'members');
        elgg_unregister_menu_item('site', 'photos');
        elgg_unregister_menu_item('site', 'pages');
        elgg_unregister_menu_item('site', 'groups');
        elgg_unregister_menu_item('site', 'translation_editor');
        elgg_unregister_menu_item('site', 'izap-videos');
        elgg_unregister_menu_item('site', 'iZap-videos');
        elgg_unregister_menu_item('site', 'iZap Videos');
        elgg_unregister_menu_item('site', 'iZap Videos');
        elgg_unregister_menu_item('site', 'Videos');
        elgg_unregister_menu_item('site', 'videos');
        elgg_unregister_menu_item('site', 'video');
        elgg_unregister_menu_item('site', 'Video');
        elgg_unregister_menu_item('site', 'elgg-menu-item-izap-videos-videos');
        elgg_unregister_menu_item('site', 'izap-videos-videos');
        elgg_unregister_menu_item('site', 'iZap-videos-videos');

        // this seems to be the class applied to the css: "elgg-menu-item-izap-videos-videos"
       // plugin folder name is izap_videos but i may've renamed that at some point ages ago

    does anyone know what it is? or how do i find it out?

    2) i cant seem to unregister the profile and friends icons..(ive been able to unregister others).
    or maybe theyre getting re-registered down the line. what's the easiest way to diagnose whom by?

     

    elgg_register_event_handler('init', 'system', 'custom_profile_icon');


    function custom_profile_icon()
    {
        elgg_unregister_menu_item('topbar', 'elgg-menu-item-profile');
        // elgg_unregister_menu_item('topbar', 'elgg-menu-item-menu-profile');

        
        $site_url = elgg_get_site_url();
        $users_name = get_loggedin_user()->username;
        $users_url = $site_url.'profile/'.$users_name;
        //$icon_url = elgg_get_site_url() . "/mod/custom_groups_icon/_graphics/icon-groups.png";
        
        $text = '<span class="elgg-icon elgg-icon-user"></span>';
        
        elgg_register_menu_item('topbar', array(
            'name' => 'menu_profile',
            'href' => "$users_url",
            'title' => 'Profile',
            'text' => $text,
        //    'text' => "<img src=\"$icon_url\" alt=\"Elgg logo\" width=\"20\" height=\"20\" />",
            'priority' => 100,
        //    'link_class' => 'elgg-icon elgg-icon-user',
        ));
    }

     

    image

  • [explanation of image]: the first two icons are both profile. i cant seem to unregister the default one.
    similarly with the next two (star and default friends). the rest are fine.

  • the icons.php is pointing to the png file in the _graphics. and if i upgrade elgg later, unless i remember to copy that folder over too i would lose it. i guess id have to maybe change where the icons.php is looking for the png file and point it to a plugin folder that will come with me

    That's correct, though you don't have to override the entire icons.php file if it's just that small change you're making, you can just redeclare the css class .elgg-icons {} with the location of your replacement image.

    Sometimes items are registered at the point of 'pagesetup' - just before all views are rendered.  You are unregistering them at the system 'init', which happens before pagesetup.  So to make sure you get them all you should unregister the items in pagesetup with a high priority (running last).

    // in my init function

    elgg_register_event_handler('pagesetup', 'system', 'myplugin_pagesetup', 1000);

     

    // global function

    function myplugin_pagesetup() {

      // unregister menu items here

    }

     

    Finally for the izap videos, underscores get converted to hyphens for class names, so it's most likely izap_videos_videos

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking