Skip to content

Commit

Permalink
Fix element fields not finding existing elements when `Relate digital…
Browse files Browse the repository at this point in the history
… products from a specific site?` was set on the field
  • Loading branch information
engram-design committed Feb 17, 2019
1 parent 32ab173 commit 5573ac1
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/fields/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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)) {
Expand Down
14 changes: 14 additions & 0 deletions src/fields/CalendarEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/fields/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions src/fields/CommerceProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/fields/CommerceVariants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/fields/DigitalProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/fields/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions src/fields/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5573ac1

Please sign in to comment.