Skip to content

Commit

Permalink
Fix structure IDs not being set for block queries, causing #174
Browse files Browse the repository at this point in the history
  • Loading branch information
ttempleton committed Jan 17, 2019
1 parent 1839ea8 commit 9bc9f83
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
5 changes: 5 additions & 0 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '')
Expand Down
14 changes: 7 additions & 7 deletions src/elements/db/BlockQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 9bc9f83

Please sign in to comment.