In some of our plugins, we have added multi-site support. For the most part, things are working fine but I'm feeling a bit confused about the correct way to set the
currentSite in the Control Panel.
On the front-end, I would expect
currentSite could be determined from the Base URL matching that of the request.
On the backend, since all admin behavior is managed from the same base domain, there is nothing specific about the request that would indicate the request is for a certain site so using something like
Craft::$app->getSites()->currentSite seems to always give back the same answer.
Does Craft define the
currentSite on backend requests? What role should a plugin take in defining the
currentSite? Should we go as far as creating the variable for current site itself or could we just set the current site using something like
Craft::$app->getSites()->setCurrentSite() and expect Craft to do several things for us? Should we expect different behavior of the
currentSite variable when working with Elements vs other components?
Understandably, these are some broad questions. I'm mostly just looking for a better framework to understand what assumptions Craft makes about multi-site on the CP side of things and how we can best plan our code to take advantage of what is already there instead of reinventing the wheel.