HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

[Tutorial] How to change the order of modules and menu items

edited October 2013 in Tutorials

To change the sort order of Modules like the who's online or categories etc. By adding the module or changing where it is

You would add these lines to your config.php

**Organizing Module Sort Order**
You can organize the order that modules appear in assets by manipulating the Modules collection of the Configuration array. Take a look at conf/config-defaults.php to see the default sort order of core-packaged modules:
// Modules
$Configuration['Modules']['Vanilla']['Panel'] = array('NewDiscussionModule', 'GuestModule', 'Ads');
$Configuration['Modules']['Vanilla']['Content'] = array('Gdn_MessageModule', 'Notices', 'Content', 'Ads');
$Configuration['Modules']['Garden']['Content'] = array('Gdn_MessageModule', 'Notices', 'Content', 'Ads');
$Configuration['Modules']['Conversations']['Content'] = array('Gdn_MessageModule', 'Notices', 'Content', 'Ads');

To Sort the menu Items you would need to add the line below to the config.php however keep in mind that some plugins may also be sorting the menu items or modules and you would need to adjust them too.

$Configuration['Garden']['Menu']['Sort'] = array('NewDiscussion','User','Dashboard','Privacy', etc.....);

Thanks to peregrine for handing me this resource :)

Tagged:

Comments

  • peregrineperegrine MVP
    edited October 2013

    yes , its for people who don't read the official vanilla documentation, but where should this info be posted for people who don't read documentation, tutorials, wiki, or the forum :) lol, or should it be col

    http://vanillaforums.org/docs/modules

    let's not forget:

    changing profile tab order

    $Configuration['Garden']['ProfileTabOrder'] = array('Votes','Comments', 'Discussions');

    maybe the vanilla forum documentation person will write a faq one day - documentation in terms of function for users. with easy to follow questions. (and at least update the documentation at minimum of annually or core release).

    1. Sorting menus, modules, tabs

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited October 2013

    In DashBoard - A few fields sort out - not all.

    $Configuration['Garden']['DashboardMenu']['Sort'] = array("Import","Users","Appearance");

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Can one change the order in other places than the config.php. What if you want a plugin, when enabled, to modify the order of the panel for example?

  • You can read and write to the config easily:

    $PluginSort = C('Garden.DashboardMenu.Sort');
    array_unshift($PluginSort, 'YourPlugin');
    SaveToConfig('Garden.DashboardMenu.Sort', $PluginSort);
    
  • @R_J, how does one discover the string you are using to specify what asset to manage? i.e. Garden.DashboardMenu.Sort? Is there a list of these somewhere?

  • It is just the config setting already mentioned by peregrine:

    @peregrine said:
    In DashBoard - A few fields sort out - not all.

    $Configuration['Garden']['DashboardMenu']['Sort'] = array("Import","Users","Appearance");

    All you have to do is to change it to a dot-separated string => 'Garden.DashboardMenu.Sort'

  • hgtonighthgtonight MVP
    edited December 2013

    Plugins can read the config and even save back to it. To read the config option @peregrine mentioned, you would use C('Garden.DashboardMenu.Sort');. To save a value back to that config option, you would use SaveToConfig('Garden.DashboardMenu.Sort', $Value);.

    Using these in tandem in the setup method would let you modify the sort order on enable. Something like this:

    public function Setup() {
      $CurrentSort = C('Garden.DashboardMenu.Sort');
    
      if(!array_key_exists('Votes') {
        // prepend the sort array with votes
        $NewSort = array_unshift($CurrentSort, "Votes");
    
        // Save the changes back to the config
        SaveToConfig('Garden.DashboardMenu.Sort', $NewSort);
      }
    }
    

    EDIT - Cross posted. @R_J is just too awesome :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • fraxturefraxture
    edited December 2013

    Okay, so this
    $Configuration['Modules']['Vanilla']['Panel']
    would be
    'Modules.Vanilla.Panel'
    ?

  • @fraxture said:
    Okay, so this
    $Configuration['Modules']['Vanilla']['Panel']
    would be
    'Modules.Vanilla.Panel'
    ?

    Yup. The periods denote a sub array.

    I think this is emulating some functionality found in JS, aka The Lord's Language. ;)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Well I've got this working writing to the config file, but it's not changing the order. What ends up getting written to config.php is:

     $Configuration['Modules']['Vanilla']['Panel'] = 'a:5:{i:0;s:12:"OKGoMeModule";i:1;s:19:"NewDiscussionModule";i:2;s:14:"SignedInModule";i:3;s:11:"GuestModule";i:4;s:3:"Ads";}';
    

    But that doesn't seem to effect the order. If I manually enter this:

     $Configuration['Modules']['Vanilla']['Panel'] = array('OKGoMeModule','NewDiscussionModule','SignedInModule','GuestModule','Ads');
    

    Then it works.

    Here's the code I'm using in the plugin:

    public function Setup() {
        $ModuleSort = C('Modules.Vanilla.Panel');
    
        if ( array_search('OKGoMeModule',$ModuleSort) === FALSE ) {
    
            array_unshift($ModuleSort, 'OKGoMeModule');
    
            SaveToConfig('Modules.Vanilla.Panel', $ModuleSort);
    
        }
    
    }
    
  • After:


    Do a print_r or var_dump or any debugging option that Vanilla / Garden gives to see what's the contents of $ModuleSort

    If that gives you a normal array (not serialized) then look in the function SaveToConfig() why it is serializing before wriying to the conf/config.php file

    There was an error rendering this rich post.

  • It is serializing the array in SaveToConfig. This is expected behavior. The unexpected behavior is in class.controller.php. It doesn't retrieve the configuration values directly, but through the modules parent array. This means it does not unserialize the array stored there.

    This is a pickle and fixing it may cause unintended consequences.

    You may be able to get a reference and bypassing the SaveToConfig method all together, but I have a feeling that won't help.

    I think a bug report is in order.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • And how does one make a bug report??

  • @fraxture said:
    And how does one make a bug report??

    Although we would love for you to find out yourself by ... reading the announcement for the Vanilla Beta version ... we would point you in the right direction if it would take too long for you to find out...

    Let's see if you can find the issue list on the Vanilla Github repo

    There was an error rendering this rich post.

  • you can also sort the menu items like this and override the config, possibly the same approach can be taken for the modules...I use this in my PrivacyNotice plugin to force the link to be the last on the list so the popup can be applied properly.

                   if (is_object($Sender->Menu))
                 $Sender->Menu->Sort = array('Privacy','Dashboard', 'Discussions', 'Questions', 'Activity', 'Applicants', 'Conversations', 'User');
    
  • @fraxture said:
    And how does one make a bug report??

    if you look for issues in underdog's signature and click on the links - that is one way to go there.
    Other than that - documentation page in vanilla and wiki have info on issuetracker
    and the announcement as underdog already mentioned.

    the key to all the semantics is "bug report" can be also called issues or "issue tracker".
    we need a tutorial on synonyms and vanilla jargon.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.