From 63e963cdbec83e84c050af168c829ebf0423ae4a Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 17 Apr 2018 04:09:55 -0700 Subject: [PATCH] Duplicate content from primary site if possible (#2748) --- CHANGELOG-v3.md | 1 + src/services/Sections.php | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index e5dc3d5b924..05dc76cbe1f 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -13,6 +13,7 @@ - Control Panel panes now have at least 48 pixels of bottom padding. ([#2744](https://github.com/craftcms/cms/issues/2744)) - Craft now intercepts 404-ing resource requests, and publishes the resources on the fly. - The Clear Caches utility now has a “Control Panel resources” option. +- When enabling new sites for a section, the new sites’ content is now based on the primary site’s content, if the section was and still is enabled for the primary site. ([#2748](https://github.com/craftcms/cms/issues/2748)) ### Fixed - Fixed a bug where the Clear Caches utility was not deleting template caches. ([#2720](https://github.com/craftcms/cms/issues/2720)) diff --git a/src/services/Sections.php b/src/services/Sections.php index cece3fbfa6d..77fd3d3e738 100644 --- a/src/services/Sections.php +++ b/src/services/Sections.php @@ -557,13 +557,19 @@ public function saveSection(Section $section, bool $runValidation = true): bool $newSiteIds = array_keys($allSiteSettings); $persistentSiteIds = array_values(array_intersect($newSiteIds, $oldSiteIds)); + // Try to make that the primary site, if it's in the list + $siteId = Craft::$app->getSites()->getPrimarySite()->id; + if (!in_array($siteId, $persistentSiteIds, false)) { + $siteId = $persistentSiteIds[0]; + } + Craft::$app->getQueue()->push(new ResaveElements([ 'description' => Craft::t('app', 'Resaving {section} entries', [ 'section' => $section->name, ]), 'elementType' => Entry::class, 'criteria' => [ - 'siteId' => $persistentSiteIds[0], + 'siteId' => $siteId, 'sectionId' => $section->id, 'status' => null, 'enabledForSite' => false,