1

I'm trying to use Redactor as a dependency for a plugin I'm writing. I need it to be installed before I run my Install.php migration, because in the migration I'm creating a Redactor field.

Following this question I tried to listen to the AFTER_LOAD_PLUGINS Event:

use craft\services\Plugins;
use yii\base\Event;
use craft\redactor\Plugin as Redactor;

class Plugin extends \craft\base\Plugin
{
    public function init()
    {
        parent::init();

        Event::on(Plugins::class, Plugins::EVENT_AFTER_LOAD_PLUGINS, function () {
            Redactor::getInstance()->install();
        });
    }
}

However Redactor::getInstance() still returns null.

1 Answer 1

2

Redactor::getInstance(), will return the instance of the plugin, only if it is already installed.

Have you tried using Craft::$app->getPlugins()->installPlugin('redactor');?

1
  • Thanks! That worked like a charm
    – Matanya
    Nov 16, 2021 at 15:56

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.