This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

vdomah
vdomah

Hi all, is there a way to reorder plugins load init order? Examining the source code make me feel that there is no such possibility but may be I'm missing something.

The purpose is to make plugins load order controllable so that I could define more complex logic in Plugin.php boot() method.

Now I'm trying to add order property to plugin.yaml file to read it in System\Classes\PluginManager in getVendorAndPluginNames() method

Last updated

daftspunky
daftspunky

You should describe in more detail why you want this feature. Then we may be able to explore possible solutions. For now we can't think of a reason why this is needed, the plugin load order shouldn't matter.

vdomah
vdomah

This feature will help with more flexible plugins extending. From real case I'm dealing with:

Say I got plugin #1 with some features and I want to enhance them with my second plugin #2. Usualy it works as it is but the problem appears when in plugin #2 I not only update some static parameters but give new instruments for extending like defining dynamic method that could be used by third plugin.

In my case in plugin #1 I got Product model. In plugin #2 I need to define new dynamic method called addFilterable() similar to addFillable() from the core. And this new method should be used in my plugin #3.

I changed code in PluginManager.php to have this feature. It works like this: in plugin.yaml we can define priority: %some_number% If priority is not defined plugin got boot priority = 0. For plugin I want make sure to be loaded earlier I can set priority: -100. So this implementation will not break the way it works now.

Last updated

mehdiestavi16508
mehdiestavi16508

when plugin#1 use addCss and plugin#2 need overwrite the CSS, priority loading is needed

vdomah
vdomah

While exploring this topic I've found that implementing loading priority could add too much ambiguity to the system and better not to use it in public plugins development.

Better to use some classes, singletons or look for some declared Events to override somethiing.

odlex
odlex

Maybe you can use the "require" parameters in plugin.php, if a plugin requires another then it will be loaded after ....

mrdezzo23970
mrdezzo23970

I agree with @vdomah, it's a critical miss imo. \System\Classes\PluginManager::registerAll does not take into account $require property. To overcome this issue, I've registered new ServiceProvider right before \System\ServiceProvider, where I call PluginManager::sortByDependencies, so the code looks like this:

        $pluginManager = PluginManager::instance();
        $sortedPlugins = $pluginManager->sortByDependencies();
        $plugins = $pluginManager->getPlugins();
        $map = [];

        foreach ($sortedPlugins as $pluginName) {
            $map[$pluginName] = $plugins[$pluginName];
        }

        $reflection = new \ReflectionProperty($pluginManager, 'plugins');
        $reflection->setAccessible(true);
        $reflection->setValue($pluginManager, $map);

1-7 of 7

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.