Questions related to replacing the original topbar with a custom one

I replaced the original topbar with my own bar because I lost my mind trying to edit the original topbar. I located it in views/default/page/elements/topbar.php
But I don't understand a few things

Is it possible to unregister the whole topbar to save on resources? The instructions say to unregister the components like this:

// Remove the "Elgg" logo from the topbar menu
elgg_unregister_menu_item('topbar', 'elgg_logo');

but how do I know (or where to find) the other strings that can be unregistered?

My current 'log out' link is simply mydomain.com/action/logout'
But the original 'log out' was much more complicated, with tokens and stuff e.g:
/action/logout?__elgg_ts=1410540736&__elgg_token=c90b15ab5877e123723be4385d6b269b
Why is it like that?

  • The topbar is not something that you can register/unregister. You're confusing views with menus.

    But you can decide not to print the topbar at all. Just remove the part where it is added as part of the page.

  • elgg_unregister_menu_item('topbar', 'logout');

    elgg_register_menu_item('topbar', array(
                'href' => '/action/logout',
                'is_action' => TRUE,
                'name' => 'logout',
                'priority' => 1000,
                'text' => elgg_echo('logout'),
            ));

  • Thanks! So I make the 'log out' link like this:

    <a href="mydomain.com/action/logout?__elgg_ts=<?php echo time(); ?>&__elgg_token=<?php echo generate_action_token($__elgg_ts); ?>" >

    Seems to work though not even the previous one gave errors.

    "But you can decide not to print the topbar at all. Just remove the part where it is added as part of the page."

    If I remove the part where it is added

    $topbar = elgg_view('page/elements/topbar', $vars);

    it removes my customized topmenu as well. I thought of just running over the original top bar and removing the extra components later but I guess it works as good like this.

  • <a href="mydomain.com/action/logout?__elgg_ts=<?php echo time(); ?>&__elgg_token=<?php echo generate_action_token($__elgg_ts); ?>" >

    Very bad solution.

    Just combine PHP and HTML.

    What's wrong with my above solution?

  • "What's wrong with my above solution?"

    I don't understand it. I don't understand the logic of Elgg menus.

    Why do you first unregister and then register elgg_unregister_menu_item('topbar', 'logout') ?

    How can you echo it? I've tried all kinds of combinations with the example line in Elgg docs:

    echo elgg_view_menu('my_menu', array('sort_by' => 'title'));

    but can't get it to be displayed.

  • @Darth Vader

    Why do you first unregister and then register elgg_unregister_menu_item('topbar', 'logout') ?

    Because this item registred by default already.

    In first, you need to unregister the 'core' items.

    Then you can register your own items.

     

    I've showed to you easiest way for customizing some items in 'topbar' menu.

    But you can combine it with your own HTML links (menus) too.

     

    How can you echo it?

    If you customize 'topbar' menu only  then you can provide it via your theme:

    function theme_pagesetup_handler() {
        elgg_unregister_menu_item('topbar', 'elgg_logo');
        elgg_unregister_menu_item('topbar', 'friends');
        elgg_unregister_menu_item('topbar', 'profile');
        elgg_unregister_menu_item('topbar', 'usersettings');
        elgg_unregister_menu_item('topbar', 'logout');
        
        elgg_register_menu_item('topbar', array(
                'href' => "/settings'/$user->username",
                'name' => 'settings'',
                'priority' => 900,
                'text' => $settings',
            ));
            
        elgg_register_menu_item('topbar', array(
                'href' => "/logout",
                'name' => 'logout',
                'priority' => 1000,
                'text' => $logout,
            ));
    }    
        e.t.c.

  • This is what my customize logout code looks like

    $ts = time();
    $token = generate_action_token($ts); 

    <a href="<?php echo elgg_get_site_url() . 'action/logout?__elgg_ts=' . $ts . '&__elgg_token=' . $token ;?>">Log Out </a>

  • @[cim]  Sure, but it's not 'Zen-coder' way ;)

  • Thank you! I've still got problems making actual changes.

    I have edited header.php to adjust the site menu for test purposes

    <?php

    function theme_pagesetup_handler() {
        elgg_unregister_menu_item('site', 'activity');
        elgg_unregister_menu_item('site', 'groups');
        elgg_unregister_menu_item('site', 'file');

        elgg_register_menu_item('site', array(
                    'href' => 'google.com',
                    'name' => 'activity',
                    'priority' => 1000,
                    'text' => elgg_echo('tree'),
                ));

         elgg_register_menu_item('site', array(
                'href' => "yahoo.com",
                'name' => 'groups',
                'priority' => 1000,
                'text' => elgg_echo('shit'),
            ));
         elgg_register_menu_item('site', array(
                'href' => "yahoo.com",
                'name' => 'file',
                'priority' => 1000,
                'text' => elgg_echo('nit'),
            ));
    }    

    // insert site-wide navigation
        echo elgg_view_menu('site');

    but none of the changes are displayed on the site menu. What am I missing?

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