diff --git a/src/fields/Assets.php b/src/fields/Assets.php index 671db012..99b61455 100644 --- a/src/fields/Assets.php +++ b/src/fields/Assets.php @@ -47,6 +47,8 @@ public function parseField() $settings = Hash::get($this->field, 'settings'); $folders = Hash::get($this->field, 'settings.sources'); $limit = Hash::get($this->field, 'settings.limit'); + $targetSiteId = Hash::get($this->field, 'settings.targetSiteId'); + $feedSiteId = Hash::get($this->feed, 'siteId'); $upload = Hash::get($this->fieldInfo, 'options.upload'); $conflict = Hash::get($this->fieldInfo, 'options.conflict'); $fields = Hash::get($this->fieldInfo, 'fields'); @@ -97,6 +99,18 @@ public function parseField() $query = AssetElement::find(); + // In multi-site, there's currently no way to query across all sites - we use the current site + // See https://github.com/craftcms/cms/issues/2854 + if (Craft::$app->getIsMultiSite()) { + if ($targetSiteId) { + $criteria['siteId'] = Craft::$app->getSites()->getSiteByUid($targetSiteId)->id; + } else if ($feedSiteId) { + $criteria['siteId'] = $feedSiteId; + } else { + $criteria['siteId'] = Craft::$app->getSites()->getCurrentSite()->id; + } + } + // If we're uploading files, this will need to be an absolute URL. If it is, save until later. // We also don't check for existing assets here, so break out instantly. if ($upload && UrlHelper::isAbsoluteUrl($dataValue)) { diff --git a/src/fields/CalendarEvents.php b/src/fields/CalendarEvents.php index c876dc50..8e8307b8 100644 --- a/src/fields/CalendarEvents.php +++ b/src/fields/CalendarEvents.php @@ -40,6 +40,8 @@ public function parseField() $settings = Hash::get($this->field, 'settings'); $sources = Hash::get($this->field, 'settings.sources'); $limit = Hash::get($this->field, 'settings.limit'); + $targetSiteId = Hash::get($this->field, 'settings.targetSiteId'); + $feedSiteId = Hash::get($this->feed, 'siteId'); $match = Hash::get($this->fieldInfo, 'options.match', 'title'); $node = Hash::get($this->fieldInfo, 'node'); @@ -83,6 +85,18 @@ public function parseField() $query = EventElement::find(); + // In multi-site, there's currently no way to query across all sites - we use the current site + // See https://github.com/craftcms/cms/issues/2854 + if (Craft::$app->getIsMultiSite()) { + if ($targetSiteId) { + $criteria['siteId'] = Craft::$app->getSites()->getSiteByUid($targetSiteId)->id; + } else if ($feedSiteId) { + $criteria['siteId'] = $feedSiteId; + } else { + $criteria['siteId'] = Craft::$app->getSites()->getCurrentSite()->id; + } + } + $criteria['status'] = null; $criteria['typeId'] = $typeIds; $criteria['limit'] = $limit; diff --git a/src/fields/Categories.php b/src/fields/Categories.php index b81bc3b2..e0e43ef8 100644 --- a/src/fields/Categories.php +++ b/src/fields/Categories.php @@ -75,7 +75,7 @@ public function parseField() // See https://github.com/craftcms/cms/issues/2854 if (Craft::$app->getIsMultiSite()) { if ($targetSiteId) { - $criteria['siteId'] = $targetSiteId; + $criteria['siteId'] = Craft::$app->getSites()->getSiteByUid($targetSiteId)->id; } else if ($feedSiteId) { $criteria['siteId'] = $feedSiteId; } else { diff --git a/src/fields/CommerceProducts.php b/src/fields/CommerceProducts.php index 0f0c8355..f3aaff08 100644 --- a/src/fields/CommerceProducts.php +++ b/src/fields/CommerceProducts.php @@ -39,6 +39,8 @@ public function parseField() $settings = Hash::get($this->field, 'settings'); $sources = Hash::get($this->field, 'settings.sources'); $limit = Hash::get($this->field, 'settings.limit'); + $targetSiteId = Hash::get($this->field, 'settings.targetSiteId'); + $feedSiteId = Hash::get($this->feed, 'siteId'); $match = Hash::get($this->fieldInfo, 'options.match', 'title'); $node = Hash::get($this->fieldInfo, 'node'); @@ -82,6 +84,18 @@ public function parseField() $query = ProductElement::find(); + // In multi-site, there's currently no way to query across all sites - we use the current site + // See https://github.com/craftcms/cms/issues/2854 + if (Craft::$app->getIsMultiSite()) { + if ($targetSiteId) { + $criteria['siteId'] = Craft::$app->getSites()->getSiteByUid($targetSiteId)->id; + } else if ($feedSiteId) { + $criteria['siteId'] = $feedSiteId; + } else { + $criteria['siteId'] = Craft::$app->getSites()->getCurrentSite()->id; + } + } + $criteria['status'] = null; $criteria['typeId'] = $typeIds; $criteria['limit'] = $limit; diff --git a/src/fields/CommerceVariants.php b/src/fields/CommerceVariants.php index 3195c3a6..b2ce4a51 100644 --- a/src/fields/CommerceVariants.php +++ b/src/fields/CommerceVariants.php @@ -39,6 +39,8 @@ public function parseField() $settings = Hash::get($this->field, 'settings'); $sources = Hash::get($this->field, 'settings.sources'); $limit = Hash::get($this->field, 'settings.limit'); + $targetSiteId = Hash::get($this->field, 'settings.targetSiteId'); + $feedSiteId = Hash::get($this->feed, 'siteId'); $match = Hash::get($this->fieldInfo, 'options.match', 'title'); $node = Hash::get($this->fieldInfo, 'node'); @@ -82,6 +84,18 @@ public function parseField() $query = VariantElement::find(); + // In multi-site, there's currently no way to query across all sites - we use the current site + // See https://github.com/craftcms/cms/issues/2854 + if (Craft::$app->getIsMultiSite()) { + if ($targetSiteId) { + $criteria['siteId'] = Craft::$app->getSites()->getSiteByUid($targetSiteId)->id; + } else if ($feedSiteId) { + $criteria['siteId'] = $feedSiteId; + } else { + $criteria['siteId'] = Craft::$app->getSites()->getCurrentSite()->id; + } + } + $criteria['status'] = null; $criteria['typeId'] = $typeIds; $criteria['limit'] = $limit; diff --git a/src/fields/DigitalProducts.php b/src/fields/DigitalProducts.php index 19732991..d6e579da 100644 --- a/src/fields/DigitalProducts.php +++ b/src/fields/DigitalProducts.php @@ -40,6 +40,8 @@ public function parseField() $settings = Hash::get($this->field, 'settings'); $sources = Hash::get($this->field, 'settings.sources'); $limit = Hash::get($this->field, 'settings.limit'); + $targetSiteId = Hash::get($this->field, 'settings.targetSiteId'); + $feedSiteId = Hash::get($this->feed, 'siteId'); $match = Hash::get($this->fieldInfo, 'options.match', 'title'); $node = Hash::get($this->fieldInfo, 'node'); @@ -83,6 +85,18 @@ public function parseField() $query = ProductElement::find(); + // In multi-site, there's currently no way to query across all sites - we use the current site + // See https://github.com/craftcms/cms/issues/2854 + if (Craft::$app->getIsMultiSite()) { + if ($targetSiteId) { + $criteria['siteId'] = Craft::$app->getSites()->getSiteByUid($targetSiteId)->id; + } else if ($feedSiteId) { + $criteria['siteId'] = $feedSiteId; + } else { + $criteria['siteId'] = Craft::$app->getSites()->getCurrentSite()->id; + } + } + $criteria['status'] = null; $criteria['typeId'] = $typeIds; $criteria['limit'] = $limit; diff --git a/src/fields/Entries.php b/src/fields/Entries.php index 66ab29a6..52a20e89 100644 --- a/src/fields/Entries.php +++ b/src/fields/Entries.php @@ -89,7 +89,7 @@ public function parseField() // See https://github.com/craftcms/cms/issues/2854 if (Craft::$app->getIsMultiSite()) { if ($targetSiteId) { - $criteria['siteId'] = $targetSiteId; + $criteria['siteId'] = Craft::$app->getSites()->getSiteByUid($targetSiteId)->id; } else if ($feedSiteId) { $criteria['siteId'] = $feedSiteId; } else { diff --git a/src/fields/Tags.php b/src/fields/Tags.php index ff86bb72..964c85f2 100644 --- a/src/fields/Tags.php +++ b/src/fields/Tags.php @@ -40,6 +40,8 @@ public function parseField() $settings = Hash::get($this->field, 'settings'); $source = Hash::get($this->field, 'settings.source'); $limit = Hash::get($this->field, 'settings.limit'); + $targetSiteId = Hash::get($this->field, 'settings.targetSiteId'); + $feedSiteId = Hash::get($this->feed, 'siteId'); $match = Hash::get($this->fieldInfo, 'options.match', 'title'); $create = Hash::get($this->fieldInfo, 'options.create'); $fields = Hash::get($this->fieldInfo, 'fields'); @@ -78,6 +80,18 @@ public function parseField() $query = TagElement::find(); + // In multi-site, there's currently no way to query across all sites - we use the current site + // See https://github.com/craftcms/cms/issues/2854 + if (Craft::$app->getIsMultiSite()) { + if ($targetSiteId) { + $criteria['siteId'] = Craft::$app->getSites()->getSiteByUid($targetSiteId)->id; + } else if ($feedSiteId) { + $criteria['siteId'] = $feedSiteId; + } else { + $criteria['siteId'] = Craft::$app->getSites()->getCurrentSite()->id; + } + } + $criteria['status'] = null; $criteria['groupId'] = $groupId; $criteria['limit'] = $limit;