October: order of initialization

Created on 17 Jul 2016  路  13Comments  路  Source: octobercms/october

How to change the boot order of plugins in the ioc?

Question

All 13 comments

Plugins are loaded in the order which they are read from the file system. It is intentional in some ways, the load order should not be important to how a plugin operates. Consider using the App::before method to defer any logic, like so:

function boot()
{
    App::before(function() { /* this will execute after all plugins have loaded */ });
}

We could consider improving this, if you wouldn't mind sharing your requirements for needing it? Thanks!

Thanks. You can add order parametr in the Plugin.php as in the function registerNavigation.

'We could consider improving this, if you wouldn't mind sharing your requirements for needing it? Thanks!'

For example if you want to extend the plugin, that already extends some plugin. The boot methods of dependency plugins should be executed first.

This is a high level description. We need a low level usage case, a simple example that demonstrates why it is needed. This will be used to see if there is not already a solution that exists.

+1

@zakir1929 plugin's already have the $depends property that is used to determine migration order, what exactly are you "+1"ing? And don't get me started on how useless "+1" comments are to GitHub discussions 馃槈

@LukeTowers Sorry for confusion by "+1"ing. I thought it is a sign for pointing the same issue which someone already experienced. I know about $depends and $require property of Plugin and they use to determine migration order.

so for explaining let me make it more easy.

I have created a plugin A which extend another plugin B but B is also extending a Plugin (in my case Rainlab.User). so what i want is to control the loading/executing order and want to execute Plugin B before Plugin A but right now plugin A is executing before plugin B.

and plugin B is already using below code inside it which @daftspunk suggested above.

function boot()
{
    App::before(function() { /* this will execute after all plugins have loaded */ });
}

and I can't touch Plugin B because it is not my Plugin.

Thanks !!!

@zakir1929 what exactly are you doing that requires Plugin B to run before Plugin A for extending it?

screenshot

@zakir1929 then remove all the fields that use that tab, add your fields, and then re-add the original fields; or modify the form config in place dynamically to reorder it as necessary.

its worked Thanks !!! @LukeTowers you helped me in 2 issues so thankyou very much.

@zakir1929 no problem!

Was this helpful? Did it save you time? Then consider becoming a Patreon supporter so I can keep providing excellent support! Or, add your thoughts to https://github.com/octobercms/october/issues/3683

Thankyou for the offer @LukeTowers right now I am very new to Octobercms so maybe I will think about it in future.

Was this page helpful?
0 / 5 - 0 ratings