Example extensions for extension developemnt

twisted1919

Administrator
Staff member
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.
 

Attachments

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.

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
 
So, it's the time to move this to kb area, was searching to find this for a while. :P
 
So, it's the time to move this to kb area, was searching to find this for a while. :p

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)

;)
 
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'. ;)
 
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:
@VVT - is your extension enabled to run in console app?
p.s: use [ code ] [ /code ] to embed code. or [ php ] code [ /php ]
 
Thanks for the reply. I think its not enabled to run in console app. Could you please tell me how can i do that
 
PHP:
public $allowedApps = array('*');

public $notAllowedApps = array();

public $cliEnabled = true;

protected $_canBeDeleted = true;

protected $_canBeDisabled = true;
 
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).
 
@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 :) ?
 
@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.
 
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).
Did you have a chance to look at this ?
 
@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',
);
 
  • Like
Reactions: VVT
@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-' . $type, compact('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($view, compact('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.
 
Back
Top