From 25178449452c908e472acdd6921370e2e94e5f88 Mon Sep 17 00:00:00 2001 From: Mat Fish Date: Wed, 6 Jul 2022 16:55:54 +0300 Subject: [PATCH] craft 4 - fix #2 --- CHANGELOG.md | 4 ++++ .../Migrators/BlogCategoriesMigrator.php | 20 +++++++++-------- src/services/SectionService.php | 22 +++++++++++-------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d5675..1d4af8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Blogify +## 2.0.2 - 2022-07-06 +### Fixed +- Multisite Support [#2](https://github.com/matfish2/craft-blogify/issues/2) + ## 2.0.1 - 2022-06-13 ### Fixed - Allow Redactor version >=3 diff --git a/src/migrations/Migrators/BlogCategoriesMigrator.php b/src/migrations/Migrators/BlogCategoriesMigrator.php index c3e7dee..eaf7a1f 100644 --- a/src/migrations/Migrators/BlogCategoriesMigrator.php +++ b/src/migrations/Migrators/BlogCategoriesMigrator.php @@ -22,14 +22,16 @@ public static function add(): bool return true; } - $siteId = Craft::$app->sites->getPrimarySite()->id; - - $siteSettings = new CategoryGroup_SiteSettings([ - 'siteId' => Craft::$app->sites->getPrimarySite()->id, - 'hasUrls' => true, - 'uriFormat' => 'blog/category/{slug}', - 'template' => 'blogify/filters/category/_entry', - ]); + $allSitesSettings = []; + + foreach (Craft::$app->getSites()->getAllSiteIds() as $siteId) { + $allSitesSettings[$siteId] = new CategoryGroup_SiteSettings([ + 'siteId' => $siteId, + 'hasUrls' => true, + 'uriFormat' => 'blog/category/{slug}', + 'template' => 'blogify/filters/category/_entry', + ]); + } $categoryGroup = new CategoryGroup([ 'name' => 'Blog Categories', @@ -37,7 +39,7 @@ public static function add(): bool ] ); - $categoryGroup->setSiteSettings([$siteId => $siteSettings]); + $categoryGroup->setSiteSettings($allSitesSettings); return Craft::$app->categories->saveGroup($categoryGroup); } diff --git a/src/services/SectionService.php b/src/services/SectionService.php index 167edb6..25641f7 100644 --- a/src/services/SectionService.php +++ b/src/services/SectionService.php @@ -20,19 +20,23 @@ public function add($name, $handle, $type, $url, $template): bool return true; } + $allSitesSettings = []; + + foreach (Craft::$app->getSites()->getAllSiteIds() as $siteId) { + $allSitesSettings[$siteId] = new Section_SiteSettings([ + 'siteId' => $siteId, + 'enabledByDefault' => true, + 'hasUrls' => true, + 'uriFormat' => 'blog' . $url, + 'template' => 'blogify/' . $template, + ]); + } + $section = new Section([ 'name' => $name, 'handle' => $handle, 'type' => $type, - 'siteSettings' => [ - new Section_SiteSettings([ - 'siteId' => Craft::$app->sites->getPrimarySite()->id, - 'enabledByDefault' => true, - 'hasUrls' => true, - 'uriFormat' => 'blog' . $url, - 'template' => 'blogify/' . $template, - ]), - ] + 'siteSettings' => $allSitesSettings ]); if (!Craft::$app->sections->saveSection($section)) {