How to change the sorting order within the "page"-plugin's sidebar's navigation?

Hello,

it's your elggnoob again with another - hopefully easy to answer - question:

This time the topic is the sidebar within the "pages" plugin.

I have adjusted the sidebar according to my ideas and have hidden the "owner block" successfully. So far, so good.

When I click on a page and that page has "sub-pages", then the sidebar offers me a block called "Navigation". In that block, it shows me all sub-pages of that page. That's exactly what I want. There is just one difficulty:

The sub-pages in this "Navigation" list are sorted chronologically, with the oldest on top and the newest at the bottom.

I tried to find out where that list originates. I think it comes from this page: /mod/pages/views/default/pages/sidebar/navigation.php. In there it calls a view called "pages_nav" with a class called "elgg-menu-page".

I browsed the Elgg core files and found the file /elgg/elgg/views/default/page/elements/page-menu.php.

I was thinking that this could be the page that the navigation.php is calling. But I guess that thought is wrong, because the page-menu.php has "sort by name" in it, not chronologically from oldest to newest.

I tried changing that parameter in both files, both, in "my plugin" and also in the core files, but to no avail.

How/where can I make the page's plugin's (or alternatively: all) sidebar's navigation lists sort alphabetically instead of chronologically from oldest to newest?

Thank you for your reply.

Kind regards,

the Elggnoob

P. S. To show that I'm not just a noobish freeloader, please find my post in the "Professional Services", thank you.

  • elgg_view_menu('pages_nav',[]) means that somewhere a menu with pages_nav name is registered.

    You can easily find it using 'Developer tools' plugin then 'Inspect -> Events'.

    So you can find this event and it shows us the menu is registered in this class.

    Now you can (1) override this class using same path, or (2) unregister this class and register your own in the custom plugin (best choice).

    Add sort_by parameter to $children = elgg_get_entities code:

    $children = elgg_get_entities([
          'type' => 'object',
          'subtype' => 'page',
          'metadata_name_value_pairs' => [
              'name' => 'parent_guid',
              'value' => $next_level_guids,
              'operand' => 'IN',
           ],
          'batch' => true,
          'sort_by' => [
            'property_type' => 'metadata',
            'property' => 'title',
            'direction' => 'ASC',
          ],
    
    ]);
    Learn more about properties for entities fetching
     
  • Thanks once again for the answer. The tip with the "developer tools" is excellent. That helps a lot.

    I followed your advice, found the file (I don't know how I missed it before, since it's quite visible within the folder structure) and tried updating it via "my plugin", just like I did with for previous topics, but unfortunately,  nothing happened this time. I also tried overriding the original file "PagesNav.php" within the "pages" plugin which always worked for my previous topics, but it also didn't change the sorting order.

    I will continue to investigate this. For now, I just wanted to post an update, in case someone else might follow this thread.

     

  • In your custom plugin:

    elgg-plugin.php

    'events' => [
        'register' => [
             'menu:pages_nav' => [
                 'Elgg\Pages\Menus\PagesNav::register' => ['unregister' => true],
                 '\MyPlugin\Pages\Menus\PagesNav::register' => ['priority' => 800],
             ],
        ],
    ],
    Copy \mod\pages\classes\Elgg\Pages\Menus\PagesNav.php to \mod\my_plugin\classes\MyPlugin\Pages\Menus\PagesNav.php
     
    PagesNav.php
     
    Change namespace on MyPlugin\Pages\Menus
    Change code mentioned in the previous reply
     
    Save and run Upgrade via administration.
     
    Check now.
  • Thank you once again for your patience and clear explanations. I appreciate it and I understand now how register/unregister works and should be able to apply it correctly by myself from now on.

    I followed your instructions and my site uses my own PagesNav now for the sidebar (as tested by making small changes there). Unfortunately, the sorting is still done via ID though, like this:

    Item 1: pages/view/586/rrr

    Item 2: pages/view/592/sss

    Item 3: pages/view/598/ddd

    I will play around with the code to see if I can find the reason, but my guess is that you will be faster. ;)

  • I found the culprit:

    The "Pages Tools" plugin must be overwriting this, despite "my plugin" being at the bottom of the list.

    After deactivating "Pages Tools", the sorting order works as intended.

    Thanks again for the help!

  • I just wanted to ask you about this )

    There is a separate event for this menu.

    You can also unregister it in your plugin instead of deactivating the plugin.

    'Elgg\Pages\Menus\PagesNav::register' => ['unregister' => true],
    '\ColdTrick\PagesTools\Menus\PagesNav::orderPagesNav' => ['unregister' => true],
    '\MyPlugin\Pages\Menus\PagesNav::register' => ['priority' => 800],

    In future, use 'Developer tools' plugin to inspect ALL same events 

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