Skip to content

No way to determine which site a global was updated in with GlobalVariableSaved event #10888

Description

@duncanmcclean

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

  1. Setup a multisite

  2. Setup a global in multiple sites

  3. Listen for the GlobalVariablesSaved event in your AppServiceProvider:

    Event::listen(GlobalVariablesSaved::class, function ($event) {
        ray($event->variables);
    });
  4. Save a global via the Control Panel

  5. See that the GlobalVariablesSaved event is dispatched multiple times - once for each site the global set is configured for.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions