<p><code>Redactor::getInstance()</code>, will return the instance of the plugin, only if it is already installed.</p>
<p>Have you tried using <code>Craft::$app-&gt;getPlugins()-&gt;installPlugin('redactor');</code>?</p>

CC BY-SA 4.0
2021-11-16T15:56:49.090Z
Thanks! That worked like a charm
Matanya
CC BY-SA 4.0
2021-11-16T12:39:08.313Z
2021-11-16T12:39:08.313Z
nstCactus
<p>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 <code>Install.php</code> migration, because in the migration I'm creating a Redactor field.</p>
<p>Following this <a href="https://craftcms.stackexchange.com/questions/33269/ns-prefix-plugingetinstance-returns-null-from-another-plugin-in-craft-3">question</a> I tried to listen to the AFTER_LOAD_PLUGINS Event:</p>
<pre class="lang-php prettyprint-override"><code>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()-&gt;install();
        });
    }
}
</code></pre>
<p>However <code>Redactor::getInstance()</code> still returns <code>null</code>.</p>

<plugin-development>
Install plugin from another plugin
# Install plugin from another plugin

(Asked by: username_0 on 2021-11-16)

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.

**Tags:** plugin-development

---

## 1 answers

### Answer by username_1 on 2021-11-16. Score: 2 | Accepted answer

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

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

> **Comments:**
> **username_0**: Thanks! That worked like a charm  

---

