Skip to content

Commit

Permalink
$isNewSite
Browse files Browse the repository at this point in the history
Better fix for #16752
  • Loading branch information
brandonkelly committed Feb 25, 2025
1 parent 68bb559 commit 7ce8b10
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,8 @@ public function attributes(): array
$names['propagating'],
$names['propagateAll'],
$names['newSiteIds'],
$names['isNewForSite'],
$names['isNewSite'],
$names['resaving'],
$names['duplicateOf'],
$names['mergingCanonicalChanges'],
Expand Down
6 changes: 6 additions & 0 deletions src/base/ElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ trait ElementTrait
*/
public bool $isNewForSite = false;

/**
* @var bool Whether this is for a newly-created site.
* @since 4.14.9
*/
public bool $isNewSite = false;

/**
* @var bool Whether the element is being resaved by a ResaveElement job or a `resave` console command.
* @since 3.1.22
Expand Down
1 change: 1 addition & 0 deletions src/fields/BaseRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ public function normalizeValue(mixed $value, ?ElementInterface $element = null):
$value instanceof ElementQueryInterface &&
$element?->propagating &&
$element->isNewForSite &&
!$element->isNewSite &&
!$this->targetSiteId &&
!$this->showSiteMenu
) {
Expand Down
7 changes: 7 additions & 0 deletions src/queue/jobs/PropagateElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class PropagateElements extends BaseBatchedJob
*/
public array|int|null $siteId = null;

/**
* @var bool Whether this is for a newly-added site.
* @since 4.14.9
*/
public bool $isNewSite = false;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -81,6 +87,7 @@ protected function processItem(mixed $item): void
/** @var ElementInterface $item */
$item->setScenario(Element::SCENARIO_ESSENTIALS);
$item->newSiteIds = [];
$item->isNewSite = $this->isNewSite;
$supportedSiteIds = array_map(fn($siteInfo) => $siteInfo['siteId'], ElementHelper::supportedSitesForElement($item));
$elementSiteIds = $this->siteId !== null ? array_intersect($this->siteId, $supportedSiteIds) : $supportedSiteIds;
$elementsService = Craft::$app->getElements();
Expand Down
3 changes: 2 additions & 1 deletion src/services/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,10 @@ public function handleChangedSite(ConfigEvent $event): void
// (skip entries because they only support specific sites)
// (skip Matrix blocks because they will be re-saved when their owners are re-saved).
$elementTypes = [
GlobalSet::class,
Asset::class,
Category::class,
Tag::class,
GlobalSet::class,
];

foreach ($elementTypes as $elementType) {
Expand All @@ -833,6 +833,7 @@ public function handleChangedSite(ConfigEvent $event): void
'siteId' => $oldPrimarySiteId,
],
'siteId' => $site->id,
'isNewSite' => true,
]));
}
}
Expand Down

0 comments on commit 7ce8b10

Please sign in to comment.