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

How to override applications/dashboard/modules/xxx.php?

Hi, guys,

I am new to vanillaforums, please someone can tell me how to override xxx.php files under applications/dashboard/modules/ folder in custom theme? Or how to modify those files that dont broke the core.

what I expect is move the Guest Welcome Message Box from Panel section to Content section in my custom theme.

Thank you!

Comments

  • K17K17 Français / French Paris, France ✭✭✭
    edited January 2021

    Hi :D

    Most modules can be modified by using plugins or themehooks. Like this you never touch the core, so your forum is always ready for updates ^^

    I may not be able to do it for you, as I'm not really talented in PHP dev, but if you want some exemples of something that actually runs, you can checkout the /themes/keystone/KeystoneThemeHooks.php to see how it works using themehooks and in any plugin folder to see how plugins are integrated.

  • Thanks, buddy

    I'll try to study at some addons to find out how it works, thanks again.

  • R_JR_J Ex-Fanboy Munich Admin

    A page in Vanilla consists of several sections called "assets", but you already know this. You could achieve what you want by copying one default.master.tpl to your theme and add {module name="GuestModule"} somewhere in the Content section. The GuestModule in the Panel would need to be hidden with some Panel.Box.GuestModule or whatever selector, you can easily find that out.


    WHOA!!! I wanted to quickly write down the code it would need to remove the module from the Panel and it to the Content. It did not work and I cannot find the reason for it! In theory, adding the below to the themehooks file should do the trick:

       public function base_beforeRenderAsset_handler($sender, $args) {
           switch ($args['AssetName']) {
               case 'Content':
                   $sender->addModule('GuestModule', 'Content');
                   break;
               case 'Panel':
                   if (array_key_exists(
                       'GuestModule',
                       $sender->Assets['Panel']['GuestModule']
                   )) {
                       unset($sender->Assets['Panel']['GuestModule']);
                   }
                   break;
           }
       }
    

    ... just to show you the nice way.


    Hackish but working is this:


       public function base_render_before($sender) {
           if ($sender->MasterView == 'admin') {
               return;
           }
    
           unset($sender->Assets['Panel']['GuestModule']);
           $sender->addModule('GuestModule', 'Content');
       }
    
  • R_JR_J Ex-Fanboy Munich Admin

    Okay, I messed up that array_key_exists, but it's not working anyhow. The hackish way is only a bit ugly, not too much. If you are interested, I could add some explanations to the code.

  • R_JR_J Ex-Fanboy Munich Admin

    I received a notification about a comment, but cannot find it. There were two questions:

           if ($sender->MasterView == 'admin') {
               return;
           }
    

    base_render_before is rendered before every page view, also before a dashboard page is shown. There is no need to show the GuestModule in the dashboard, so this snippet should prevent further code execution in the dashboard.

    The second question concerned the module sort order in the content. I'm not sure about that, but there is a config setting which might help you. You can find it in a the config-defaults, but don't change it there.

    // Module visibility and sorting.
    $Configuration['Modules']['Vanilla']['Panel'] = ['MeModule', 'UserBoxModule', 'GuestModule', 'NewDiscussionModule', 'DiscussionFilterModule', 'SignedInModule', 'Ads'];
    $Configuration['Modules']['Vanilla']['Content'] = ['MessageModule', 'MeModule', 'UserBoxModule', 'NewDiscussionModule', 'ProfileOptionsModule', 'Notices', 'NewConversationModule', 'NewDiscussionModule', 'DiscussionFilterModule', 'CategoryModeratorsModule', 'Content', 'Ads'];
    

    Copy the last line into the config and add the GuestModule at the beginning of the array. I hope it helps.

  • Thank you again, @R_J.

    Now I understand the whole code you provided and my problem was finally solved.

    First, I unset the GuestModule in Panel section, and then add {module name="GuestModule"} to my custom theme file default.master.tpl in a appropriate position.



Sign In or Register to comment.