Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Update for critical security issue in PHPMailer included in release Vanilla 2.3.1

Example plugin don't work

This discussion is related to the example addon.

When I enable it, whole the forum is going down.

Comments

  • madimadi New

    Hi, try to put this line into conf/config.php

    $Configuration['Garden']['Debug'] = TRUE;

    Then, you will able to see the error and resolved.
    Br, madi

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Please use this file: https://raw.githubusercontent.com/vanilla/addons/release/2.2/plugins/example/class.example.plugin.php

    The problem lies here:

       public function AssetModel_StyleCss_Handler($Sender) {
          $Sender->AddCssFile('example.css', 'plugins/Example');
          $Sender->AddJsFile('example.js', 'plugins/Example');
       }
    

    You would be able to continue with the example plugin you have if you delete the $Sender->AddJsFile('example.js', 'plugins/Example'); line.

    whu606
  • @madi said:
    Hi, try to put this line into conf/config.php

    $Configuration['Garden']['Debug'] = TRUE;

    Then, you will able to see the error and resolved.
    Br, madi

    Thx for pointing that. Actually if one want to see the log, he should also put this two lines:

    $Configuration['Garden']['Errors']['LogEnabled'] = TRUE;
    $Configuration['Garden']['Errors']['LogFile'] = 'log/error_log';

    to the config.php AND create a folder named 'log/'

  • @R_J said:
    Please use this file: https://raw.githubusercontent.com/vanilla/addons/release/2.2/plugins/example/class.example.plugin.php

    The problem lies here:

       public function AssetModel_StyleCss_Handler($Sender) {
          $Sender->AddCssFile('example.css', 'plugins/Example');
          $Sender->AddJsFile('example.js', 'plugins/Example');
       }
    

    You would be able to continue with the example plugin you have if you delete the $Sender->AddJsFile('example.js', 'plugins/Example'); line.

    It works just fine. Can you please explain WHY?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    @PutinStudio said:
    It works just fine. Can you please explain WHY?

    Because the files were not being called due to wrong format in the code for adding files to the head of the document.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    The short answer is: the AssetModel has no AddJsFile method. But if you would be able to understand that answer, you wouldn't have asked ;-)

    So the long answer is really long. I guess you do not really know where that public function AssetModel_StyleCss_Handler($Sender) { comes from and so I have to explain something about events and hooks in Vanilla.

    When you want to extend Vanillas functionality, you should hook into events which are fired. Normally when an event is fired, there are also some arguments passed.
    If you want to find out which events are available and what arguments get passed, you have to look at Vanillas source code.

    In order to hook into an event you need to create a method in your plugin and that method must follow a naming convention. The method has to consist of three parts, separated by an underscore: className_eventName_handler
    The first part is the name of the class that fires an event and the second part is the name of the event. The last part is always "handler".
    When you look at some plugins, you will see that almost every method has two parameters $sender and $args.

    $sender is always the instance of the class that the event fired. $args is an array containing all values that has been passed to the EventArguments array (look at some of Vanillas classes and you will understand that quickly).

    Now that you know about the naming convention and that $sender is an instance of the class that fired the event, you should be able to find out why the code in the example plugin is erroneous.
    The method that had a wrong line in it is defined like that: public function AssetModel_StyleCss_Handler($Sender) {
    So there must be a class called AssetModel somewhere. Vanilla has exactly one class in a file and the file name convention is class.classname.php. You would have to find a file called class.assetmodel.php. Search for it and open it.
    In that file, there will be an event fired which is called "StyleCss". You have that file opened, now search for that string in this file. Great. So in the moment that event is fired, the above method in the example plugin is called and an instance of the AssetModel is passed as the first argument to the plugins method.
    The plugin has two rows in this method, $Sender->AddCssFile and $Sender->AddJsFile.
    You can "translate" that to AssetModel->AddCssFile and AssetModel->AddJsFile (sort of...)

    I hope you still have the class.assetmodel.php opened? Great. Search for its method "AddCssFile" to understand what the line in the plugin is doing.
    And now, search for "AddJsFile"...

    (dramatic break)

    The AssetModel has no AddJsFile method!
    (See? That is the short answer from the start =) )

    PutinStudio
Sign In or Register to comment.