1

I'm trying to follow along with the guide on creating custom notification events in a plugin found here: https://sprout.barrelstrengthdesign.com/docs/email/custom-notification-events.html#register-event

I used their example Manual class as my notification and now I'm trying to register it, however, I get an error of:

Class barrelstrength\sproutbase\app\email\services\NotificationEmailEvents' not found.

I checked and made sure that the sprout email is installed and enabled and also my plugin is installed and enabled.

Below is what is in my main plugin file:

namespace mycompany\plugin;

use myname\company\notifications\Manual as PluginManualNotification;

use barrelstrength\sproutbase\app\email\services\NotificationEmailEvents;
use barrelstrength\sproutbase\app\email\events\NotificationEmailEvent;

use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;

use yii\base\Event;

class MyPlugin extends Plugin
{
    public static $plugin;
    public $schemaVersion = '1.0.0';

    public function init()
    {
        parent::init();
        self::$plugin = $this;

        Event::on(
            Plugins::class,
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
            function (PluginEvent $event) {
                if ($event->plugin === $this) {
                    // We were just installed.
                }
            }
        );

        Event::on(
            NotificationEmailEvents::class,
            NotificationEmailEvents::EVENT_REGISTER_EMAIL_EVENT_TYPES,
            function (NotificationEmailEvent $event) {
                $event->events[] = PluginManualNotification::class;
            }
        );
    }

    /* Create settings modal and other unrelated stuff */
}
Mr.Smithyyy
  • 175
  • 6

1 Answers1

2

The docs at the time of the question reference an old classname in the C3 example, the two Notification Email related classes in your code are now in a module named sprout-base-email:

NEW
use barrelstrength\sproutbaseemail\services\NotificationEmailEvents;
use barrelstrength\sproutbaseemail\base\NotificationEvent;

OLD
use barrelstrength\sproutbase\app\email\services\NotificationEmailEvents;
use barrelstrength\sproutbase\app\email\events\NotificationEmailEvent;

Ben Parizek
  • 13,448
  • 1
  • 33
  • 98
  • This brings up a new error for me: Argument 1 passed to myPlugin\{closure}() must be an instance of barrelstrength\sproutbaseemail\base\NotificationEmailEvent, instance of barrelstrength\sproutbaseemail\events\NotificationEmailEvent given which is strange because I am not using barrelstrength\sproutbaseemail\events anywhere in my plugin. – Mr.Smithyyy Dec 12 '19 at 14:14