Easiest way to get current site in php block

Hi, which is the easiest way to get current site and available sites data in php block?
Like in twig you have:

{{ this.site.id }}
{{ this.site.name }}
{{ this.site.code }}
{{ this.site.locale }}
{{ this.site.timezone }}
{{ this.site.theme }}

I’m using the Site Facade, like this:

Site::getSiteFromContext();
Site::listSites():

Isn’t there any $this->....?
Just wanted to check if that was the easiest and more direct way. In twig it seems pretty straight forward.

use System\Classes\SiteManager;
$activeSite = SiteManager::instance()->getSiteFromContext()

1 Like

Hi, thanks, is there any difference from using the Site Facade?

Not really; the Site class is a facade for the SiteManager instance.

Hi,

Does anyone know if it is possible to get the active site from the boot() method of a custom plugin in the Plugin.php file?

Whatever I do, I always get back the primary site, instead of the site the user is currently on.

    public function boot()
    {
        $activeSite = Site::getActiveSite();
        Log::info('Active site: '.$activeSite->code);
    }

My goal is to have a link to a specific product on a specific subsite, but with a variable locale, so I can reuse that as a variable in pages and emails without duplicate code.

My logic might be flawed though.
Any thoughts?