From 9bc9f8318e16fcb663375c578ac74293b9afd9be Mon Sep 17 00:00:00 2001 From: Thomas Templeton Date: Fri, 18 Jan 2019 00:48:02 +1100 Subject: [PATCH] Fix structure IDs not being set for block queries, causing #174 --- CHANGELOG.md | 4 ++++ composer.json | 4 ++-- package.json | 2 +- src/Field.php | 5 +++++ src/elements/db/BlockQuery.php | 14 +++++++------- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd43f4f5..6da2232b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.1.5 - 2019-01-17 +### Fixed +- Fixed issue where structure IDs were not being set for block queries, causing duplicated blocks to appear in Craft 3.1.0 and newer + ## 2.1.4 - 2019-01-13 ### Fixed - Fixed issue on multi-site Craft installs where entry/category fields in new or pasted/cloned Neo blocks were always listing elements from the primary site diff --git a/composer.json b/composer.json index a0c6bddb..29a46266 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "spicyweb/craft-neo", "description": "A Matrix-like field type that uses existing fields", - "version": "2.1.4", + "version": "2.1.5", "type": "craft-plugin", "keywords": [ "cms", @@ -25,7 +25,7 @@ "rss": "https://github.com/spicywebau/craft-neo/commits/master.atom" }, "require": { - "craftcms/cms": "^3.0.17" + "craftcms/cms": "^3.0.31" }, "autoload": { "psr-4": { diff --git a/package.json b/package.json index e094fa53..176f63ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "craft-neo", - "version": "2.1.4", + "version": "2.1.5", "description": "A Matrix-like field type that uses existing fields", "main": "webpack.config.js", "scripts": { diff --git a/src/Field.php b/src/Field.php index dc754f0c..11caa1df 100644 --- a/src/Field.php +++ b/src/Field.php @@ -297,6 +297,11 @@ public function normalizeValue($value, ElementInterface $element = null) ->fieldId($this->id) ->siteId($element->siteId ?? null); + if ($this->localizeBlocks) + { + $query->ownerSiteId($element->siteId ?? null); + } + // Set the initially matched elements if $value is already set, which is the case if there was a validation // error or we're loading an entry revision. if (is_array($value) || $value === '') diff --git a/src/elements/db/BlockQuery.php b/src/elements/db/BlockQuery.php index 9122e60f..f03db695 100644 --- a/src/elements/db/BlockQuery.php +++ b/src/elements/db/BlockQuery.php @@ -373,15 +373,15 @@ protected function beforePrepare(): bool ->scalar(); } } + } - if (!$this->structureId && $this->fieldId && $this->ownerId && $this->ownerSiteId) - { - $blockStructure = Neo::$plugin->blocks->getStructure($this->fieldId, $this->ownerId, $this->ownerSiteId); + if (!$this->structureId && $this->fieldId && $this->ownerId) + { + $blockStructure = Neo::$plugin->blocks->getStructure($this->fieldId, $this->ownerId, $this->ownerSiteId); - if ($blockStructure) - { - $this->structureId = $blockStructure->structureId; - } + if ($blockStructure) + { + $this->structureId = $blockStructure->structureId; } }