Bug description
There's currently no way to know which site's globals were updated for when listening to the GlobalVariablesSaved event, as the event gets dispatched for all of the global set's configured sites.
I considered adding an InitiatorStack, like we have for entries, which could keep track of the initially updated global. However, due to the way that global sets and variables get saved, I couldn't get it to work.
A future solution to this might be to call save() on the Variables object directly, rather than go through the GlobalSet::save() method (which is what ends up looping through and saving each localization right now).
| $save = $set->globalSet()->addLocalization($set)->save(); |
^ However, this would mean introducing a breaking change, so it can't be done until Statamic 6.
How to reproduce
Setup a multisite
Setup a global in multiple sites
Listen for the GlobalVariablesSaved event in your AppServiceProvider:
Event::listen(GlobalVariablesSaved::class, function ($event) {
ray($event->variables);
});Save a global via the Control Panel
See that the GlobalVariablesSaved event is dispatched multiple times - once for each site the global set is configured for.
Bug description
There's currently no way to know which site's globals were updated for when listening to the
GlobalVariablesSavedevent, as the event gets dispatched for all of the global set's configured sites.I considered adding an
InitiatorStack, like we have for entries, which could keep track of the initially updated global. However, due to the way that global sets and variables get saved, I couldn't get it to work.A future solution to this might be to call
save()on theVariablesobject directly, rather than go through theGlobalSet::save()method (which is what ends up looping through and saving each localization right now).cms/src/Http/Controllers/CP/Globals/GlobalVariablesController.php
Line 107 in 346acb7
^ However, this would mean introducing a breaking change, so it can't be done until Statamic 6.
How to reproduce
Setup a multisite
Setup a global in multiple sites
Listen for the
GlobalVariablesSavedevent in yourAppServiceProvider:Save a global via the Control Panel
See that the
GlobalVariablesSavedevent is dispatched multiple times - once for each site the global set is configured for.