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.

can I add a criteria to a module?

I wanna add criterias to a module in the themehooks file.

I've tried a lot of method, but still didn't find out.

for example:

{module name="PromotedContentModule" Selector="role" ContentType="discussions" Selection="administrator" Limit="3" BodyLimit="90"}

I need to add above criterias to the following function:

 public function discussionController_BeforeFirstComment_handler($Sender) {
         // 
        $PromotedContentModule = new PromotedContentModule();
        echo $PromotedContentModule->toString();

    }

Best Answer

  • R_JR_J Ex-Fanboy Munich Admin
    Answer ✓

    Great question! =)

    The {module... syntax is a custom Smarty function. If you look it up you will find that it points towards class Theme, method module. In that method you will find the following code

                    $Properties = array_merge($ControllerProperties, $Properties);
    
                    foreach ($Properties as $Name => $value) {
                        // Check for a setter method
                        if (method_exists($Module, $method = 'set'.ucfirst($Name))) {
                            $Module->$method($value);
                        } else {
                            $Module->$Name = $value;
                        }
                    }
    

    Without further testing, I would expect that in your example {module name="PromotedContentModule" Selector="role" ContentType="discussions" Selection="administrator" Limit="3" BodyLimit="90"} you would need a module which implemets the following methods:

    • setSelector
    • setContentType
    • setSelection
    • setLimit
    • setBodyLimit

    If that methods are not implemented, you should be able to access the values directly as properties of your module.


    Oh wait, your question has been the other way around. But then it is just the other way around:

         public function discussionController_beforeFirstComment_handler($sender) {
                $promotedContentModule = new PromotedContentModule($sender);
    
                if (method_exists('setSelector')) {
                    $promotedContentModule->setSelector('role');
                } else {
                    $promotedContentModule->Selector = 'role';
                }
                //Repeat for every parameter...
    
                echo $promotedContentModule->toString();
            }
    

Answers

  • R_JR_J Ex-Fanboy Munich Admin
    Answer ✓

    Great question! =)

    The {module... syntax is a custom Smarty function. If you look it up you will find that it points towards class Theme, method module. In that method you will find the following code

                    $Properties = array_merge($ControllerProperties, $Properties);
    
                    foreach ($Properties as $Name => $value) {
                        // Check for a setter method
                        if (method_exists($Module, $method = 'set'.ucfirst($Name))) {
                            $Module->$method($value);
                        } else {
                            $Module->$Name = $value;
                        }
                    }
    

    Without further testing, I would expect that in your example {module name="PromotedContentModule" Selector="role" ContentType="discussions" Selection="administrator" Limit="3" BodyLimit="90"} you would need a module which implemets the following methods:

    • setSelector
    • setContentType
    • setSelection
    • setLimit
    • setBodyLimit

    If that methods are not implemented, you should be able to access the values directly as properties of your module.


    Oh wait, your question has been the other way around. But then it is just the other way around:

         public function discussionController_beforeFirstComment_handler($sender) {
                $promotedContentModule = new PromotedContentModule($sender);
    
                if (method_exists('setSelector')) {
                    $promotedContentModule->setSelector('role');
                } else {
                    $promotedContentModule->Selector = 'role';
                }
                //Repeat for every parameter...
    
                echo $promotedContentModule->toString();
            }
    
  • Thank you again =)
    Awesome support

Sign In or Register to comment.