public function onCollectLayout(CollectLayoutEvent $event)
    {
        if (!$this->siteManager->hasContext()) {
            return;
        }

        $layoutIds  = [];
        $context    = $event->getContext();
        $site       = $this->siteManager->getContext();
        $theme      = $site->getTheme();
        $storage    = $context->getLayoutStorage();

        /*
         * Collect site layout
         */

        $siteLayoutIds = $this
            ->database
            ->query(
                "select id from {layout} where site_id = ? and node_id is null",
                [$site->getId()]
            )
            ->fetchCol()
        ;

        if (!$siteLayoutIds) {
            // Automatically create regions for site
            foreach (RegionConfig::getSiteRegionList($theme) as $region) {
                $layoutIds[] = $storage->create(['site_id' => $site->getId(), 'region' => $region])->getId();
            }
        } else {
            $layoutIds = array_merge($layoutIds, $siteLayoutIds);
        }

        /*
         * Collect current node layouts, if any
         */

        if (arg(0) === 'node' && !arg(2) && ($node = menu_get_object())) {

            $nodeLayoutIds = $this
                ->database
                ->query(
                    "select id from {layout} where node_id = ? and site_id = ?",
                    [$node->nid, $site->getId()]
                )
                ->fetchCol()
            ;

            if (!$nodeLayoutIds) {
                // Automatically creates new layout for node if none exist
                foreach (RegionConfig::getPageRegionList($theme) as $region) {
                    $layoutIds[] = $storage->create(['node_id' => $node->nid, 'site_id' => $site->getId(), 'region' => $region])->getId();
                }
            } else {
                $layoutIds = array_merge($layoutIds, $nodeLayoutIds);
            }
        }

        if ($layoutIds) {
            $event->addLayoutList($layoutIds);
        }
    }
public function onCollectLayout(CollectLayoutEvent $event)
    {
        if (!$this->siteManager->hasContext()) {
            return;
        }

        $layoutIds  = [];
        $context    = $event->getContext();
        $site       = $this->siteManager->getContext();
        $theme      = $site->getTheme();
        $storage    = $context->getLayoutStorage();

        /*
         * Collect site layout
         */

        $siteLayoutIds = $this
            ->database
            ->query(
                "select id from {layout} where site_id = ? and node_id is null",
                [$site->getId()]
            )
            ->fetchCol()
        ;

        if (!$siteLayoutIds) {
            // Automatically create regions for site
            foreach (RegionConfig::getSiteRegionList($theme) as $region) {
                $layoutIds[] = $storage->create(['site_id' => $site->getId(), 'region' => $region])->getId();
            }
        } else {
            $layoutIds = array_merge($layoutIds, $siteLayoutIds);
        }

        /*
         * Collect current node layouts, if any
         */

        if (arg(0) === 'node' && !arg(2) && ($node = menu_get_object())) {

            $nodeLayoutIds = $this
                ->database
                ->query(
                    "select id from {layout} where node_id = ? and site_id = ?",
                    [$node->nid, $site->getId()]
                )
                ->fetchCol()
            ;

            if (!$nodeLayoutIds) {
                // Automatically creates new layout for node if none exist
                foreach (RegionConfig::getPageRegionList($theme) as $region) {
                    $layoutIds[] = $storage->create(['node_id' => $node->nid, 'site_id' => $site->getId(), 'region' => $region])->getId();
                }
            } else {
                $layoutIds = array_merge($layoutIds, $nodeLayoutIds);
            }
        }

        if ($layoutIds) {
            $event->addLayoutList($layoutIds);
        }
    }
public function onCollectLayout ( CollectLayoutEvent $ event ) { if ( ! $ this -> siteManager -> hasContext ( ) ) { return ; } $ layoutIds = [ ] ; $ context = $ event -> getContext ( ) ; $ site = $ this -> siteManager -> getContext ( ) ; $ theme = $ site -> getTheme ( ) ; $ storage = $ context -> getLayoutStorage ( ) ; /*
         * Collect site layout
         */ $ siteLayoutIds = $ this -> database -> query ( "select id from {layout} where site_id = ? and node_id is null" , [ $ site -> getId ( ) ] ) -> fetchCol ( ) ; if ( ! $ siteLayoutIds ) { // Automatically create regions for site foreach ( RegionConfig :: getSiteRegionList ( $ theme ) as $ region ) { $ layoutIds [ ] = $ storage -> create ( [ 'site_id' => $ site -> getId ( ) , 'region' => $ region ] ) -> getId ( ) ; } } else { $ layoutIds = array_merge ( $ layoutIds , $ siteLayoutIds ) ; } /*
         * Collect current node layouts, if any
         */ if ( arg ( 0 ) === 'node' && ! arg ( 2 ) && ( $ node = menu_get_object ( ) ) ) { $ nodeLayoutIds = $ this -> database -> query ( "select id from {layout} where node_id = ? and site_id = ?" , [ $ node -> nid , $ site -> getId ( ) ] ) -> fetchCol ( ) ; if ( ! $ nodeLayoutIds ) { // Automatically creates new layout for node if none exist foreach ( RegionConfig :: getPageRegionList ( $ theme ) as $ region ) { $ layoutIds [ ] = $ storage -> create ( [ 'node_id' => $ node -> nid , 'site_id' => $ site -> getId ( ) , 'region' => $ region ] ) -> getId ( ) ; } } else { $ layoutIds = array_merge ( $ layoutIds , $ nodeLayoutIds ) ; } } if ( $ layoutIds ) { $ event -> addLayoutList ( $ layoutIds ) ; } }
Collects current page layout
Collects current page layout