default content tab

Is there a way to change the default tab of content? I mean the three tabs – All / Mine / Friends – used for activity, blogs, bookmarks and other contents, with All as default.
Earlier, various modifications were dealt with – to remove one, merge two of them etc. But the system has changed since then.
I would need to set the default to be Friends (or Mine) instead of All. In fact, it didn't matter much to have the All tab for most of contents. But in case of bookmarks, supposed to be a highly personal collection, it seems unsuitable to show All first. I've tried to modify this but it ended up changing only the header of the tabs while the real content remained that for All, i.e. inappropriate.
 

  • Re-register this hook:

    'menu:filter:filter' => [
          'Elgg\Menus\Filter::registerFilterTabs' => ['priority' => 1],
    ],
  • If you want your users to land on the friends tab when they click on the site menu item Bookmarks or if they type in http://yoursite/bookmarks the best way to do that is to change the configuration of the route 'default:object:bookmark'.

    If you change the resource to 'bookmark/friends' it should all work I think

    https://github.com/Elgg/Elgg/blob/26469980e5a255c5d8a2418b969e1489cb483087/mod/bookmarks/elgg-plugin.php#L29-L32

    you can use the 'route:config', 'default:object:bookmark' hook to change the config. Make sure you register your hook in the 'load' function of your bootstrap.

  • Using the default:object doesn't function. I started with trying this modification earlier.
    In the file elgg-plugin.php — change:
    'default:object:bookmarks' => [
    'path' => '/bookmarks',
    'resource' => 'bookmarks/all',]
    → to →
    'default:object:bookmarks' => [
    'path' => '/bookmarks',
    'resource' => 'bookmarks/friends',
    
    It throws an inaccessible page:
    The content you were trying to access has been removed or you do not have permissions to access it.
    The same for other modules, not only the bookmarks.
  • As Jerome said, you should use the 'route:config', 'default:object:bookmark' hook to change the config.

    You should add this hook to boot()  function in your Boostrap class.

    Why? Because you try to override the core's rotes names.

    If you need to redefine tabs globally, use my above method.

  • In which file? Bootstrap.class or elgg-plugin.php to be remade? I have tried both but haven't succeeded so far. What does that

    ['priority' => 1]

    mean?
     

  • I assume you want to make the "Friends" tab the first one in the list.
    I also assume that you want to do it globally on the site.


    Before you start, keep in mind that this tab will only be available to logged in users. Of course the "Friends" plugin must also be activated.

    If you open this file you will see that 2 menu items are defined. Each of them has its own priority: the "All" tab has 200; the "Mine" tab has 300.

    Priority means the sequence in which tabs are displayed on the site.

    If you open this file (it's for the "Friends" tab), you'll see that the priority is 400.

    So you need to set the priority of this tab to below 200 that it's ahead of the "All" tab.
    For example, 150.

    You need to unregister the current class and register your own.

    You must do it in elgg-plugin.php of your custom plugin.

    Please learn about the sections of this file.

    'Friends' filter tab is registered in the /mod/friends/elgg-plugin.php.

    Unregister it in your elgg-plugin.php and register your custom class:

    'hooks' => [
       'register' => [
           'menu:filter:filter' => [
                 '\Elgg\Friends\Menus\Filter::registerFilterTabs' => ['unregister' => true],
                 '\MyPlugin\Friends\Menus\Filter::registerFilterTabs' => ['priority' => 1],
          ],
       ],
    ],
    Clone Elgg\Friends\Menus\Filter.php file as MyPlugin\Friends\Menus\Filter.php and edit registerFilterTabs function - just change priority 400 on 150.
     
    Don't forget to delete all other functions.
    (I'm sure you know PHP).
     
    That's all!
     
    Last note: your custom plugin must be below all other plugins (on the 'plugins' page) because priority ;)
  • Well. I've just tried. But it only changed the order – the Friends tab became the first. It did not get it selected as default.

  • You must redefine the links to make the menu look like the selected one, i.e. you go to 'page/all', so the "All" menu tab will be selected.

    This is what Jerome wrote about.

    I advise you to use this method instead of changing filter tabs.

    In elgg-plugin.php:

    'routes' => [
           'default:object:bookmarks' => [
                 'path' => '/bookmarks/{username}',
                 'resource' => 'bookmarks/friends',
                 'required_plugins' => [
                      'friends',
                 ],
            ],
    
          'collection:object:bookmarks:all' => [
               'path' => '/bookmarks/all/{username}',
               'resource' => 'bookmarks/friends',
               'required_plugins' => [
                     'friends',
               ],
         ],
    ],
    Since resource 'bookmarks/friends' requires a username, you also need to add {username} to 'all' links as provided above.
     
    Learning Elgg API, Elgg documentation and searching the community would solve your problem faster than asking here.
  • In fact, I have studied plenty of documents, in this case e.g. these discussions and plugins related to the tabs, particularly concerning merges and removals of tabs, which could give a hint about the matter of the default tab setting.

    https://elgg.org/discussion/view/1145896/is-there-a-php-file-to-edit-and-customize-the-activity-page
    http://elgghacks.com/questions/view/581/how-to-combine-own-following-river-activity-tabs-into-one
    https://elgg.org/discussion/view/1531418/removing-allminefriends-tabs
    https://elgg.org/discussion/view/1160515/how-to-add-a-new-tab-to-pages-only-after-all-mine-friends
    https://elgg.org/plugins/811355
    https://elgg.org/plugins/728870
    https://elgg.org/plugins/875359

    However, it remained unclear, impossible to infer a solution from the data provided. The presented experience is insufficient. And, of course, all is aggravated by the version incompatibility: start.php → elgg-plugin.php, the new array returned instead of registering functions, new use of Bootstrap etc. The new variant seems much less documented than the old one.

    Your proposal doesn't serve it either. You can try.
    We can't use paths such as:

    'path' => '/bookmarks/{username}'
    'path' => '/bookmarks/all/{username}'

    They don't exist with a user's ID . We need a generic path:

    'path' => '/bookmarks/'

    And when setting the resource to friends:

    'resource' => 'bookmarks/friends'

    then the resource file

    /views/default/resources/bookmarks/friends.php

    doesn't receive the relevant user's ID.
    So, the whole page becomes unavailable.

    Anyway, after some experimenting, I've just found a solution.
    1) In the file elgg-plugin.php really change the resource from all to friends.
    2) In the resource file friends.php
    replace  

    elgg_extract('username', $vars)  with  elgg_get_logged_in_user_entity()->username

    or

    elgg_get_page_owner_entity()  with  elgg_get_logged_in_user_entity()

    – depending on the original content.

    This enables the script to identify the user while not requiring an external input from URL or elgg-plugin.php.
    And, of course, it can be used not only with the Bookmarks but with other modules too, as I've tried.
    So, it seems solved now.