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

Modules

ddumontddumont ✭✭
I'd love to know more about them.
Can plugins contribute them? If so, how?

There was an error rendering this rich post.

Best Answer

  • LincLinc Detroit Admin
    Answer ✓
    My way of thinking of them is a mini self-contained view you can easily tuck inside any asset like the 'Panel' (sidebar) or 'Foot'. They're like a more flexible (for a programmer) type of WordPress widget.

Answers

  • LincLinc Detroit Admin
    Yes, check out Tagging for a good example of bundling a module with a plugin.
  • LincLinc Detroit Admin
    Answer ✓
    My way of thinking of them is a mini self-contained view you can easily tuck inside any asset like the 'Panel' (sidebar) or 'Foot'. They're like a more flexible (for a programmer) type of WordPress widget.
  • So I did get one up and running by declaring the module class inside my plugin class file... Does the plugin code pick these module classes out elsewhere so they can be referenced by name instead of having to instantiate them myself?

    There was an error rendering this rich post.

  • @Lincoln ... nifty. I had to put the class in the root plugin folder. I was putting it in a folder called "modules"

    Next question, is there an easier way to contribute a sort order other than the config?

    There was an error rendering this rich post.

  • LincLinc Detroit Admin
    Tagging does it manually by including the file then instantiating. I don't *think* a plugin can just grab a module by name because I think the framework only allows Applications to use modules automatically like that. However, @Tim would be the guy to know for sure.
  • @Lincoln
    I'm currently doing:
    	
    public function Base_Render_Before($Sender) {
    if (Gdn::Session()->CheckPermission("Plugins.WWDiary.View")) {
    $Sender->AddJsFile($this->GetResource('js'.DS.'common.js', FALSE, FALSE));
    $Sender->AddCssFile($this->GetResource('design'.DS.'style.css', FALSE, FALSE));
    $Sender->AddModule('SubscribeModule');
    }
    }
    and the subscribe module is in another class.subscribemodule.php along side the plugin class file.

    There was an error rendering this rich post.

  • LincLinc Detroit Admin
    Things are rendered in assets in the order they were added. However, $this->Assetsis a public variable in the controller, so you could conceivable rearrange the array however you like. I'd use the BeforeRenderAsset hook.
  • LincLinc Detroit Admin
    @ddumont Nice! Looks like we improved module discovery and Tagging wasn't updated.
  • @Lincoln Hrmm...
    $Sender->AddModule('SubscribeModule');
    // Move the SubscribeModule to the top of the Panel
    $PanelAssets = $Sender->Assets["Panel"];
    array_unshift($PanelAssets, array_pop($PanelAssets));
    doesn't seem to be working... is that what you meant?

    There was an error rendering this rich post.

  • @Lincoln silly me... Assets is associative.
    What controls the order?

    There was an error rendering this rich post.

  • ddumontddumont ✭✭
    edited October 2011
    Looks like this gets me to the point where the configs are working for me:

    public function Base_Render_Before($Sender) {
    if (Gdn::Session()->CheckPermission("Plugins.WWDiary.View")) {
    $Sender->AddJsFile($this->GetResource('js'.DS.'common.js', FALSE, FALSE));
    $Sender->AddCssFile($this->GetResource('design'.DS.'style.css', FALSE, FALSE));
    $Sender->AddModule('SubscribeModule');

    // Move the SubscribeModule to the top of the Panel (See config.php)
    if ($Sender->ModuleSortContainer == "") {
    $Sender->ModuleSortContainer = "Vanilla";
    }
    }
    }
    Before, the config settings weren't doing anything.

    There was an error rendering this rich post.

Sign In or Register to comment.