Skip to content

Commit

Permalink
add multisite support (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Jul 6, 2022
1 parent 79a79a9 commit 74325b1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Blogify

## 1.0.9 - 2022-07-06
### Fixed
- Multisite Support [#2](https://github.com/matfish2/craft-blogify/issues/2)

## 1.0.8 - 2021-11-26
### Changed
- Seeding: Randomize post date
Expand Down
20 changes: 12 additions & 8 deletions src/migrations/Migrators/BlogCategoriesMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,26 @@ public static function add(): bool
return true;
}

$siteId = Craft::$app->sites->getPrimarySite()->id;
$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',
]);
}

$siteSettings = new CategoryGroup_SiteSettings([
'siteId' => Craft::$app->sites->getPrimarySite()->id,
'hasUrls' => true,
'uriFormat' => 'blog/category/{slug}',
'template' => 'blogify/filters/category/_entry',
]);

$categoryGroup = new CategoryGroup([
'name' => 'Blog Categories',
'handle' => Handles::CATEGORIES,
]
);
blogify_log("Setting Category group site settings...");

$categoryGroup->setSiteSettings([$siteId => $siteSettings]);
$categoryGroup->setSiteSettings($allSitesSettings);

return Craft::$app->categories->saveGroup($categoryGroup);
}
Expand Down
22 changes: 13 additions & 9 deletions src/services/SectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 74325b1

Please sign in to comment.