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.

Unsetting LatestPostListModule

r0obertr0obert
edited July 2014 in Vanilla 2.0 - 2.8

I used unset($Sender->Assets['Panel']['LatestPostListModule']); and it doesn't work. All other modules working though.

I'm on vanilla v2.1 and trying to unset LPL v1.5.3 on Basic Pages v2.1.3.

basicpages/settings/class.hooks.php code:

         public function PageController_Render_Before($Sender) {
                $Page = $Sender->Data('PageData');

                if($Page->UrlCode === $testpage) {
                    unset($Sender->Assets['Panel']['NewDiscussionModule']);
                    unset($Sender->Assets['Panel']['RecentActivityModule']);
                    unset($Sender->Assets['Panel']['DiscussionsModule']);
                    unset($Sender->Assets['Panel']['DiscussionFilterModule']);
                    unset($Sender->Assets['Panel']['GuestModule']);
                    unset($Sender->Assets['Panel']['LatestPostListModule']);

                   }
        }

Comments

  • ShadowdareShadowdare r_j MVP
    edited July 2014

    The PageData object has been renamed to Page starting with Basic Pages 2.1.2. The $testpage variable in your pasted code has to be defined or you can just put in the UrlCode directly like if($Page->UrlCode === 'example-page') {.

    In any case, from looking at the LatestPostList code, it looks like the module doesn't get loaded on the PageController at all.

    I also recommend that you create a separate plugin or a ThemeHooks file for custom mods for your forum instead of modifying another addon's hooks file, so you can update addons easily without having to replace changes you made.

    Add Pages to Vanilla with the Basic Pages app

  • r0obertr0obert
    edited July 2014

    @Shadowdare very interesting. It works with PageData but I guess it shouldn't in 2.1.3 right?

    Also when I put $testpage it unsets the modules on all pages I create using BasicPages. Why is that?

    Is there any other way of unsetting LatestPostList without using css?

    PS: Btw could my other issue related to the endless refresh of pages be related with the fact that I only used css to hide modules instead of unset? (eg. display:none to all pretty much)

  • ShadowdareShadowdare r_j MVP
    edited July 2014

    Here is an explanation of what happens when the code you posted is run:

    public function PageController_Render_Before($Sender) {
        $Page = $Sender->Data('PageData');
    

    At this point, PageData doesn't exist, so calling $Sender->Data('PageData') will return the default value returned by the Data method, which is an empty string ''.

        if($Page->UrlCode === $testpage) {
    

    $Page->UrlCode will return null because the UrlCode property doesn't exist as $Page is not an object. $testpage is an undeclared variable so it has a value of null. The condition $Page->UrlCode === $testpage translates to null === null which is true, so the code within the if block will run.

    CSS rules like display: none; are not able to cause an infinite refresh, so that's probably not the issue.

    @hgtonight, is the LatestPostList module supposed to load up on all controllers?

    Add Pages to Vanilla with the Basic Pages app

  • hgtonighthgtonight ∞ · New Moderator

    LPL has the ability to load the module on all controllers.

    The reason it doesn't seem to work is because the LPL hook hasn't been run yet. When multiple plugins/applications/themehooks use the same event hook, they are fired off in alphabetical order based on their key.

    Basicpages comes before LatestPostList.

    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.

  • @hgtonight so if the LPL hook hasn't been run yet, is there any way other than css to unset it?

  • peregrineperegrine MVP
    edited July 2014

    .

    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 July 2014

    to show on all frontend pages but a basic page.

    in class.latertpost.plugin.php

    // if we want to be on all pages, skip the check
            // otherwise leave if we aren't in an approved controller
            if ($Pages != 'all' && !InArrayI($Controller, $ShowOnController) ) {
                return;
            }
    
                    if($Controller == "pagecontroller")  return;
    

    if you wanted to prevent viewing on a specific page but all other basic pages

        if ($Pages != 'all' && !InArrayI($Controller, $ShowOnController) ) {
                return;
            }
    
                     // prevent load of module on page whudunnit
                     $uri =  $_SERVER['REQUEST_URI'];
                     if (preg_match("!page/whodunnit!", $uri))  return;
    

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

  • Works, thanks!

  • ShadowdareShadowdare r_j MVP
    edited July 2014

    I'll just leave this here: one way to avoid modifying addons and the Vanilla core code in order to upgrade those addons and the core easier is to create a plugin with a name that starts with the letter 'z' or something like that.

    Add Pages to Vanilla with the Basic Pages app

Sign In or Register to comment.