2

I'm building a plugin that extends the functionality of the Contact Form Tuner plugin and customize the email recipients based on different scenarios. The email addresses need to be managed in the plugin settings using forms. Thus, I need to grab the settings from my plugin to be used in the Contact Form Tuner config file.

The problem I'm having is that I can't access my plugin from the Contact Form Tuner config file. The getInstance method returns null. I know I have the namespace and class name right because the same statement works when running it from my plugin class.

I also noticed that Contact Form Tuner seems to be loading before my plugin when testing with die statements in both plugins. Is this the reason?

Is there any way around this?

Any help is appreciated. Thanks!

1 Answer 1

1

I also noticed that Contact Form Tuner seems to be loading before my plugin when testing with die statements in both plugins. Is this the reason?

This.

You're probably doing this from your plugin's init() function. If you listen to the EVENT_AFTER_LOAD_PLUGINS event and do your logic there, it should work.

2
  • That worked perfectly Brad thank you. For those in need of sample code, it's: use craft\services\Plugins; use yii\base\Event; Event::on(Plugins::class, Plugins::EVENT_AFTER_LOAD_PLUGINS, $callback);
    – biko
    Commented Dec 14, 2019 at 15:36
  • I'm still getting null on getInstance: Event::on(Plugins::class, Plugins::EVENT_AFTER_LOAD_PLUGINS, function () { \craft\redactor\Plugin:getInstance()->install(); });
    – Matanya
    Commented Nov 16, 2021 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.