Skip to content

Commit

Permalink
craft 4 - fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Jul 6, 2022
1 parent 67c657b commit 2517844
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 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

## 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
Expand Down
20 changes: 11 additions & 9 deletions src/migrations/Migrators/BlogCategoriesMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@ 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',
'handle' => Handles::CATEGORIES,
]
);

$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 2517844

Please sign in to comment.