Example extensions for extension developemnt

Discussion in 'Extensions' started by twisted1919, May 19, 2016.

  1. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,109
    Likes Received:
    2,348
    Hey guys,

    In order to make extensions development easier and much clear, i have attached an example extension that you can use to develop your own extensions.
    It contains very clear examples on how to:
    - make the extension available only for certain apps: customer / frontend / backend / api / console
    - hook in one/more of the above apps
    - hook into existing actions / hooks
    - add your own settings page
    - add a simple menu link
    - load your own controllers
    - override mailwizz controllers with yours
    - add a simple landing page
    And more. It is also very very well commented so that it is very clear how everything works.

    I hope this will help people that are in doubt on how to create mailwizz extensions.
    Thanks.
     

    Attached Files:

  2. frm.mwz

    frm.mwz Well-Known Member

    Joined:
    Mar 8, 2016
    Messages:
    3,705
    Likes Received:
    676
    S.E:
    2019-11-27 02:17:39
    L.T:
    Regular
    L.C:
    7
    Oh...awesome (now only time is an excuse)...I wish one could press LIKE for this unlimited times, I would write a script to run forever :D
     
  3. VVT

    VVT Active Member

    Joined:
    May 22, 2015
    Messages:
    499
    Likes Received:
    138
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    2
    So, it's the time to move this to kb area, was searching to find this for a while. :p
     
  4. frm.mwz

    frm.mwz Well-Known Member

    Joined:
    Mar 8, 2016
    Messages:
    3,705
    Likes Received:
    676
    S.E:
    2019-11-27 02:17:39
    L.T:
    Regular
    L.C:
    7
    would be great if the forum search would also search the kb (?)

    copy to kb and improve,
    but leave all intact here and open for further discussion, as users will have questions, and then have to start anew...
    otherwise you cut out history, and the discussion cannot be followed anymore, and over time it will create holes in the forum, as there are also (thought) links between threads, etc...by all means, keep consistency! look at OS versions when those bozos tear everything apart and then users suffer forever and switch...

    kb editing should be done by users for users (of course always checked if correct, so that has to be as nice as on wiki), as otherwise the perspective is incomplete!

    put differently, if a question has not been answered, then the kb is incomplete
    (especially if a repeated question has insufficiently representative examples)

    ;)
     
  5. VVT

    VVT Active Member

    Joined:
    May 22, 2015
    Messages:
    499
    Likes Received:
    138
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    2
    Yeah, right, I didn't mean to delete it from forum, I was there in the other discussion. But is handy when these stuffs are available under where it's supposed to be. So changing my word from 'move' to 'copy'. ;)
     
    frm.mwz likes this.
  6. VVT

    VVT Active Member

    Joined:
    May 22, 2015
    Messages:
    499
    Likes Received:
    138
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    2
    I just made a custom extension and it is working fine with every apps except console. I have registered the command class from extension like this
    PHP:
    if ($this->isAppName('console')) {
            
    Yii::app()->commandMap['reminder'] = array(
                
    // remember the ext-example path alias?
                
    'class'     => 'ext-example.console.commands.ReminderCommand',
              
                
    // pass the extension instance as a variable to the controller
                
    'extension' => $this,
            );
    }
    But, it is not working when I try to run the command. It is working perfectly fine if I add the command class directly to apps/console/config/main.php like this

    PHP:
    'commandMap' => array(
         
    'reminder' => array(
            
    'class'     => 'ext-example.console.commands.ReminderCommand',
          )
    ),
    Please correct me if I am missing something
     
    Last edited by a moderator: Aug 18, 2016
    frm.mwz likes this.
  7. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,109
    Likes Received:
    2,348
    @VVT - is your extension enabled to run in console app?
    p.s: use [ code ] [ /code ] to embed code. or [ php ] code [ /php ]
     
  8. VVT

    VVT Active Member

    Joined:
    May 22, 2015
    Messages:
    499
    Likes Received:
    138
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    2
    Thanks for the reply. I think its not enabled to run in console app. Could you please tell me how can i do that
     
  9. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,109
    Likes Received:
    2,348
    Post here the entire extension code without the contents of the run() method.
     
  10. VVT

    VVT Active Member

    Joined:
    May 22, 2015
    Messages:
    499
    Likes Received:
    138
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    2
    PHP:
    public $allowedApps = array('*');

    public 
    $notAllowedApps = array();

    public 
    $cliEnabled true;

    protected 
    $_canBeDeleted true;

    protected 
    $_canBeDisabled true;
     
  11. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,109
    Likes Received:
    2,348
    That looks good, not sure why exactly it fails. Till i get the chance to test and see, you can copy the main.php file into main-custom.php file and place your command there, in the components area (you can remove rest of the components from the main-custom.php).
     
  12. VVT

    VVT Active Member

    Joined:
    May 22, 2015
    Messages:
    499
    Likes Received:
    138
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    2
    @twisted1919
    Hey Buddy,

    Thanks for the new release, loving it :) I saw your comments that PCNTL was fixed, so goooood to hear :) , I didn't have a chance to try that out yet. Btw, I came here to check if the above hook issue was resolved :) ?
     
  13. Ernesto

    Ernesto Member

    Joined:
    Dec 22, 2016
    Messages:
    31
    Likes Received:
    2
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    3
    @twisted1919 Where should I put the example files and how should I run it?
    Or please point me to the documentation or forum post I should read for this.
    Thanks.
     
  14. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,109
    Likes Received:
    2,348
    @Ernesto - Just upload the example.zip archive as an extension in mailwizz and enable it. It will be uploaded in apps/extensions folder where you will be able to modify it as you wish.
    Let me know if you need more info.
     
  15. VVT

    VVT Active Member

    Joined:
    May 22, 2015
    Messages:
    499
    Likes Received:
    138
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    2
    Did you have a chance to look at this ?
     
  16. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,109
    Likes Received:
    2,348
    @VVT - Yes i did, use something like this:
    PHP:
    Yii::app()->getCommandRunner()->commands['example'] = array(
        
    // remember the ext-example path alias?
        
    'class' => 'ext-example.console.commands.ExampleCommand',
    );
     
    VVT likes this.
  17. VVT

    VVT Active Member

    Joined:
    May 22, 2015
    Messages:
    499
    Likes Received:
    138
    S.E:
    Expired
    L.T:
    Extended
    L.C:
    2
    Perfect, let me try that. Thank you !
     
  18. joegmail

    joegmail New Member

    Joined:
    Apr 1, 2017
    Messages:
    23
    Likes Received:
    8
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1
    hey @twisted1919,

    do you think it is possible to create a new DeliveryServer a child class of DeliveryServer.php using extensions?
     
  19. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,109
    Likes Received:
    2,348
    @joegmail - it should be possible, you can follow the steps at https://kb.mailwizz.com/articles/add-a-new-delivery-server-type/ but place the code in your extension.

    The only problem i see right now is that there is no hook in the create/update actions in the controller that would allow you to overwrite the view file being loaded which would render your form fields for the server, so right now, in actionCreate() and actionUpdate() last line is:
    PHP:
    $this->render('form-' $typecompact('server''policy''policies''canSelectTrackingDomains'));
    Which will not match any file and you'll get an error because of that.

    What i did now in dev, i have added a hook like this:
    PHP:
    // 1.3.9.5
    $view Yii::app()->hooks->applyFilters('delivery_servers_form_view_file''form-' $type$server$this);
    $this->render($viewcompact('server''policy''policies''canSelectTrackingDomains'));
    So basically, from your extension you can do:
    PHP:
    Yii::app()->hooks->addFilter('delivery_servers_form_view_file', function($view$server$controller)) {
        if ( 
    $server->type == 'my-custom-server-type' ) {
            
    $view Yii::getPathOfAlias('root.apps.extensions.my-extension-name.views.my-custom-server-type');
        }
        return 
    $view;
    }
    If you don't want to wait for the upcoming release, you can add the hook manually in the controller, for both, the customer and backend area. They will be safe at upgrades since i have added them too.
     
    joegmail likes this.
  20. joegmail

    joegmail New Member

    Joined:
    Apr 1, 2017
    Messages:
    23
    Likes Received:
    8
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    1

Share This Page