Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Basic Pages - Recent Discussions shown next page

Love the Basic Pages application! :-)

I wonder why 'Recent Discussions' are shown next to my page - instead of 'Categories'(as when in discussions view) or nothing is shown in the side(as in categories view)?

What did I miss / do wrong or how can I change it?

Thanks in advance.

Comments

  • edited May 2019

    Thank you for using the Basic Pages app!

    Those are just the modules I decided to include on the page view. A page is a different content type than discussions on your website and the "Recent Discussions" module seems like a better fit than the "Categories" module because the categories don't relate to the filtering of pages. The "Discussion Filter" module, which displays navigation links to categories, recent discussions, and activity, is also included.

    If I recall correctly, you may be able to override or modify the list of modules loaded on the PageController through an event handler in a separate addon. Alternatively, you can hide certain modules or the entire sidebar on the page view via CSS rules in your theme.

    Add Pages to Vanilla with the Basic Pages app

  • KasparKaspar ✭✭✭
    edited May 2019

    Thank you.

    I commented the below out - so I still have the filtermenu.

    /basicpages/controllers/class.pagecontroller.php

    89 /** $this->AddModule('NewDiscussionModule'); **/
    90     $this->AddModule('DiscussionFilterModule');
    91 /** $this->AddModule('BookmarkedModule'); **/
    92 /** $this->AddModule('DiscussionsModule'); **/
    93 /** $this->AddModule('RecentActivityModule'); **/
    


    Have no idea how to go about "override or modify the list of modules loaded on the PageController through an event handler in a separate addon."


    For others seeking similar solution - I changed:

        $this->AddModule('NewDiscussionModule');
        $this->AddModule('DiscussionFilterModule');
        $this->AddModule('BookmarkedModule');
        $this->AddModule('DiscussionsModule');
        $this->AddModule('RecentActivityModule');
    

    to

        /** $this->AddModule('NewDiscussionModule'); **/
            $this->AddModule('DiscussionFilterModule');
        /** $this->AddModule('BookmarkedModule'); **/
        /** $this->AddModule('DiscussionsModule'); **/
        /** $this->AddModule('RecentActivityModule'); **/
    


  • edited May 2019

    I recommend using single-line comments (//) instead if you're only commenting one line at a time as is the case within in your snippet above for convenience and readability; only use multi-line comments (/* ... */) when commenting out a multiple lines of code together.

    So, what you showed is one way to remove those modules, but the problem with modifying the actual file is that updates to the Basic Pages app could replace your changes and you'd have to redo it all over again. A better way would be to unset the modules--credits to @hgtonight for posting this solution a while back--from the Panel asset in the controller via a custom plugin or theme hooks.

    For example, your custom plugin can contain code like this:

    public function pageController_render_before($sender) {
        $panel = &$sender->Assets['Panel'];
    
        unset($panel['NewDiscussionModule'], $panel['BookmarkedModule'], $panel['DiscussionsModule'], $panel['RecentActivityModule']);
    }
    

    I might remove the BookmarkedModule from Basic Pages in the future and leave the rest.

    Add Pages to Vanilla with the Basic Pages app

  • KasparKaspar ✭✭✭

    It is not working for me.

    I believe this is the right way now?

    &$sender > $sender
    

    I tried with both.


    I have:

    /plugins/UnsetModules/

    addon.json

    {
        "type": "addon",
        "key": "UnsetModules",
        "description": "Unset modules for 'Basic Pages' pages",
        "version": "0.1",
        "mobileFriendly": true,
        "authors": [
            {
                "name": "Kaspar"
            }
        ]
    }
    

    class.UnsetModules.php

    <?php
    class UnsetModulesPlugin extends Gdn_Plugin {
    public function pageController_render_before($sender) {
         $panel = $sender->Assets['Panel'];
    
        unset($panel['NewDiscussionModule'], $panel['BookmarkedModule'], $panel['DiscussionsModule'], $panel['RecentActivityModule']);
    }
    }
    

    Tried with and without <?php - as that is not stated in the documentation you linked.

    Tried with Gdn_Plugin and Gdn_Controller


    Have cleared cache, plugin enables without any error in all cases.


    Have tried both UnsetModules and unsetmodules for folder, file, key and class (using the later cause the plugin enable-toogle not actually visually move to be enabled - but is enabled if page is refreshed - but no error-message).


    even if it worked, wouldn't unset for every page?


    Thanks in advance.

  • BleistivtBleistivt Moderator

    Try renaming class.UnsetModules.php to class.UnsetModulesPlugin.php

  • R_JR_J Admin

    shouldn't it be either "class.unsetmodules.plugin.php" or "UnsetModulesPlugin.php"?

    @Kaspar: you might have to delete /cache/addon.php after renaming the file

  • KasparKaspar ✭✭✭

    Thanks to you both.

    I now have the following which work (only affects the Pages pages).


    /plugins/UnsetModules

    addon.json

    {
        "type": "addon",
        "key": "unsetmodules",
        "description": "Unset modules for 'Basic Pages' pages",
        "version": "0.1",
        "mobileFriendly": true,
        "authors": [
            {
                "name": "Kaspar"
            }
        ]
    }
    

    class.Unsetmodules.php

    <?php
    class UnsetModulesPlugin extends Gdn_Plugin {
    public function pageController_render_before($sender) {
         $panel = &$sender->Assets['Panel'];
    
        unset($panel['NewDiscussionModule'], $panel['BookmarkedModule'], $panel['DiscussionsModule'], $panel['RecentActivityModule']);
    }
    }
    

    Note &$sender instead $sender

    I gather I tried with &$sender - did not work

    Tried $sender(removing &) - and perhaps added

    <?php
    

    at the same time - then never tried with both & and <?php in place.

    (& in place but <?php removed does not work)

    <?php is not mentioned in the docs - I'll file an issue about it later today.

  • KasparKaspar ✭✭✭

    I knew I had read somewhere that &$sender was deprecated.

    https://open.vanillaforums.com/discussion/21003/fyi-for-vanilla-2-1-looks-like-sender-in-your-plugin-is-not-only-deprecated

    In the code snippet Shadowdare initialy introduced here both &$sender and $sender is used - what is the difference?

  • R_JR_J Admin

    Using the ampersand is a normal operator in php for referencing a variable and has nothing to do with vanilla

    $a = $b

    If $b has value 1, $a will have it, too. But if you make $a = 2, $b will not change

    $a = &$b

    Change $a and $b changes, too

  • edited May 2019

    &$sender as a parameter in Vanilla's magic methods was deprecated and perhaps doesn't work that way now since it already passes itself by reference.

    In my example, I created the variable $panel = &$sender->Assets['Panel']; so we don't have to type out the full line for each module to be unset for readability. It must be assigned by reference (sometimes typed out as =& as well) as assigning to the array directly would basically create a copy of it once something has been modified; we want to modify the original array.

    By the way, if you want to unset modules for a specific page, you can do this:

    public function pageController_render_before($sender) {
        $page = $sender->data('Page');
        $panel = &$sender->Assets['Panel'];
    
        if ($page->PageID === 1) { // change PageID from 1 to whatever page ID you want to unset modules on
            unset($panel['NewDiscussionModule'], $panel['BookmarkedModule'], $panel['DiscussionsModule'], $panel['RecentActivityModule']);
        }
    }
    

    I haven't tested the above out yet. I just typed it out here, but it should work.

    Additionally, if there were a lot of modules on the page, you could store the module names you want to unset in an array and then loop through and unset each using the value at each index. This should help keep the code clean.

    Also, I think the documentation assumes that the reader has some basic knowledge of PHP. All PHP files should start with <?php unless you're outputting HTML first.

    Add Pages to Vanilla with the Basic Pages app

  • KasparKaspar ✭✭✭

    Giving a tiny bit back to the community :-)


Sign In or Register to comment.