src/Multisites.php
public function getActiveSite()
    {
        $controller = Controller::curr();
        if ($controller instanceof CMSPageEditController) {

            // requests to admin/pages/edit/EditorToolbar/viewfile?ID=XX
            // are not reliable because $controller->currentPage()
            // will return an incorrect page based on the ID $_GET parameter
            if ($controller->getRequest()->param('ID') != 'viewfile') {
                $page = $controller->currentPage();

                if (!$page) {
                    // fixes fatal error when duplicating page
                    // TODO find the root of the problem...
                    return Site::get()->first();
                }

                if ($page instanceof Site) {
                    $this->setActiveSite($page);
                    return $page;
                }

                $site = $page->Site();

                if ($site->ID) {
                    $this->setActiveSite($site);
                    return $site;
                }
            }
        } else if (is_subclass_of($controller, ModelAdmin::class)) {
            // if we are in a model admin that isn't using the global active_site_session,
            // return it's ActiveSite. This is important for cases where a multisite aware
            // data object is being saved for the first time in a model admin, we need to
            // know what site to save it to
            if (!$controller->config()->use_active_site_session) {
                return $controller->getActiveSite();
            }
        }

        if ($id = $controller->getRequest()->getSession()->get('Multisites_ActiveSite')) {
            return Site::get()->byID($id);
        }

        // if($id = Session::get('MultisitesModelAdmin_SiteID')) { // legacy
        // 	return Site::get()->byID($id);
        // }

        return $this->getCurrentSite();
    }
public function getActiveSite()
    {
        $controller = Controller::curr();
        if ($controller instanceof CMSPageEditController) {

            // requests to admin/pages/edit/EditorToolbar/viewfile?ID=XX
            // are not reliable because $controller->currentPage()
            // will return an incorrect page based on the ID $_GET parameter
            if ($controller->getRequest()->param('ID') != 'viewfile') {
                $page = $controller->currentPage();

                if (!$page) {
                    // fixes fatal error when duplicating page
                    // TODO find the root of the problem...
                    return Site::get()->first();
                }

                if ($page instanceof Site) {
                    $this->setActiveSite($page);
                    return $page;
                }

                $site = $page->Site();

                if ($site->ID) {
                    $this->setActiveSite($site);
                    return $site;
                }
            }
        } else if (is_subclass_of($controller, ModelAdmin::class)) {
            // if we are in a model admin that isn't using the global active_site_session,
            // return it's ActiveSite. This is important for cases where a multisite aware
            // data object is being saved for the first time in a model admin, we need to
            // know what site to save it to
            if (!$controller->config()->use_active_site_session) {
                return $controller->getActiveSite();
            }
        }

        if ($id = $controller->getRequest()->getSession()->get('Multisites_ActiveSite')) {
            return Site::get()->byID($id);
        }

        // if($id = Session::get('MultisitesModelAdmin_SiteID')) { // legacy
        // 	return Site::get()->byID($id);
        // }

        return $this->getCurrentSite();
    }
public function getActiveSite ( ) { $ controller = Controller :: curr ( ) ; if ( $ controller instanceof CMSPageEditController ) { // requests to admin/pages/edit/EditorToolbar/viewfile?ID=XX // are not reliable because $controller->currentPage() // will return an incorrect page based on the ID $_GET parameter if ( $ controller -> getRequest ( ) -> param ( 'ID' ) != 'viewfile' ) { $ page = $ controller -> currentPage ( ) ; if ( ! $ page ) { // fixes fatal error when duplicating page // TODO find the root of the problem... return Site :: get ( ) -> first ( ) ; } if ( $ page instanceof Site ) { $ this -> setActiveSite ( $ page ) ; return $ page ; } $ site = $ page -> Site ( ) ; if ( $ site -> ID ) { $ this -> setActiveSite ( $ site ) ; return $ site ; } } } else if ( is_subclass_of ( $ controller , ModelAdmin :: class ) ) { // if we are in a model admin that isn't using the global active_site_session, // return it's ActiveSite. This is important for cases where a multisite aware // data object is being saved for the first time in a model admin, we need to // know what site to save it to if ( ! $ controller -> config ( ) -> use_active_site_session ) { return $ controller -> getActiveSite ( ) ; } } if ( $ id = $ controller -> getRequest ( ) -> getSession ( ) -> get ( 'Multisites_ActiveSite' ) ) { return Site :: get ( ) -> byID ( $ id ) ; } // if($id = Session::get('MultisitesModelAdmin_SiteID')) { // legacy // 	return Site::get()->byID($id); // } return $ this -> getCurrentSite ( ) ; }
Get's the site related to what is currently being edited in the cms
If a page or site is being edited, it will look up the site of the sitetree being edited,
If a MultisitesAware object is being managed in ModelAdmin, ModelAdmin will have set a Session variable MultisitesModelAdmin_SiteID
@return Site
Get s the site related to what is currently being edited in the cms If a page or site is being edited it will look up the site of the sitetree being edited If a MultisitesAware object is being managed in ModelAdmin ModelAdmin will have set a Session variable MultisitesModelAdmin_SiteID