How to add a new tab to Pages only after All, Mine, Friends

In my Elgg 1.8 I'm using two Google map plugins: Map of Members and Share Maps, both of Nikos Lyberakis (http://elgg.lyberakis.gr/).

The first one is showing memebrs on Google Maps, based on "location" field. It's working very well but I didn't like that was adding a Members Map menu, so I wanted to add a simple tab in the Members menu after Newest, Popular, Online.

To do this I worked on the file nav.php in /www/mod/members/views/default/members where i added the following code:

'membersmap' => array(
        'title' => elgg_echo('membersmap:label:map'),
        'url' => "membersmap/map",
        'selected' => $vars['selected'] == 'membersmap',
    ),

Then in /www/mod/members/languages/en.php I added: 'members:label:map' => 'Map',

Finally to remove the "Map of Members" menu I didn't like I changed from "register" to "unregister" the following code in /www/mod/membersmap/start.php

    // Site navigation
    $item = new ElggMenuItem('membersmap', elgg_echo('membersmap:menu'), 'membersmap/all');
    elgg_unregister_menu_item('site', $item);

 

I was very happy and I was immediatelly planning to do the same for the other Share Maps plugin in the Pages menu, but I found out that the Pages menu is working in a different way from the Members one :(

At the moment I have been able to create and modify mod/pages/views/default/page/layouts/content/filter.php so I got my extra tab but this tab is appearing after All, Mine, Friends also in all the other menus such as Activity, Blogs and Bookmarks, but I don't want this!

I was trying to override only mod/pages/ adding views/default/page/layouts/content/filter.php but it's effective also on the other menus :(

Any suggestion how to move on???

As you can see I'm able to read and adjust parts of code but I'm not a programmer nor expert of Elgg so please give me step by step suggestions.

Thanks in advance ;)

  • You need to create your own filter menu.

    Copy views\default\page\layouts\content\filter.php in to your own theme and then override it.

    Don't touch the core's files (as members, pages etc).

    Just create your own theme/plugin and write your code once without reapeating in to many Elgg mods.

  • @RvR thanks for the reply.

    I did as you suggested (at least I guess so) but the result is the same ...

    I moved filter.php from mod/pages/views/default/page/layouts/content/ to mod/[mytheme]/views/default/page/layouts/content/

    but the new tab is still appearing after All, Mine, Friends also in all the other menus such as Activity, Blogs and Bookmarks, but I want it to be only in Pages ...

    How can I limit the effect of my filter menu only to Pages?

    Thanks again for you support!

     

  • did you change the order of your theme in the plugins list?

  • Yes, my theme is the last plugin in the list and it's working but this is not the problem ...

    The point is: if I want that my new filter.php overrides only the "Pages" menu and not also "Activity", "Blogs" and "Bookmarks" what should I do?

    I get the new tab after All, Mine, Friends everywhere and I want it only in "Pages" ...

  • then you'll want to use the elgg get context function

    if((elgg_get_context() == 'pages')) {
    // put new filter here
    else {
    // put the default filter here

  • Hi Cim,

    thanks a lot for your tip, after a short time to find the correct syntax I got it working :)

    Now I have two more issues and I can't find any clear solution in the forum ...

    I placed my "New Tab" as first before the "All" tab so I'd like to set it as default one, but where can I change the default tab from "All" to "New Tab"? and I guess also in this case I'll have to use the elgg get context function ...

    Then I have a problem linking the "New Tab" to sharemaps plugin page. I started using the function:

    'url' => "sharemaps/all",

    But it's not working ... should I use 'href' instead of 'url' as the other tabs in filter.php?

    Thanks for your continued support!

  • @stefano Sure, 'href' only!

    Try this plugin as example for development your own tabs

  • Ok, I'll check how to use 'href' to link the "New Tab" to my sharemaps plugin page ...

    Anybody can suggest where can I change the default tab from "All" to my "New Tab"?

  • In views\default\page\layouts\content\filter.php

    $tabs = array(
            'all' => array(
                'text' => elgg_echo('all'),
                'href' => (isset($vars['all_link'])) ? $vars['all_link'] : "$context/all",
                'selected' => ($filter_context == 'all'),
                'priority' => 200,
            ),
            'mine' => array(
                'text' => elgg_echo('mine'),
                'href' => (isset($vars['mine_link'])) ? $vars['mine_link'] : "$context/owner/$username",
                'selected' => ($filter_context == 'mine'),
                'priority' => 300,
            ),
            'friend' => array(
                'text' => elgg_echo('friends'),
                'href' => (isset($vars['friend_link'])) ? $vars['friend_link'] : "$context/friends/$username",
                'selected' => ($filter_context == 'friends'),
                'priority' => 400,
            ),
        );

  • Thanks RvR but I can't see where I can change the dafault tab (the one shown as I open the page) ...

    My filter.php looks like this:

    if ((elgg_get_context() == 'pages')) {
            $tabs = array(
                'sharemaps' => array(
                    'text' => elgg_echo('sharemaps:label:map'),
                    'href' => "sharemaps/view/74/kite-spots",
                    'selected' => ($filter_context == 'sharemaps'),
                    'priority' => 200,
                ),
                'all' => array(
                    'text' => elgg_echo('all'),
                    'href' => (isset($vars['all_link'])) ? $vars['all_link'] : "$context/all",
                    'selected' => ($filter_context == 'all'),
                    'priority' => 300,
                ),
                'mine' => array(
                    'text' => elgg_echo('mine'),
                    'href' => (isset($vars['mine_link'])) ? $vars['mine_link'] : "$context/owner/$username",
                    'selected' => ($filter_context == 'mine'),
                    'priority' => 400,
                ),
                'friend' => array(
                    'text' => elgg_echo('friends'),
                    'href' => (isset($vars['friend_link'])) ? $vars['friend_link'] : "$context/friends/$username",
                    'selected' => ($filter_context == 'friends'),
                    'priority' => 500,
                ),
            );
          }

     

    As you can see I used the function 'priority' => to place my sharemaps tab before the "All" tab, but "All" is still the default one ...

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