Skip to content

Commit

Permalink
Block structure fixes (#143, #148)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttempleton committed Nov 2, 2018
1 parent ceb2ae0 commit eb7c20a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/elements/db/BlockQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ protected function beforePrepare(): bool
$this->subQuery->andWhere(Db::parseParam('neoblocks.typeId', $this->typeId));
}

$this->query->groupBy('{{elements}}.uid');

return parent::beforePrepare();
}

Expand Down
15 changes: 15 additions & 0 deletions src/services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public function saveValue(Field $field, ElementInterface $owner, bool $isNew)

if (!$hasBlocks)
{
$duplicatedBlocks = [];

foreach ($blocks as $block)
{
$duplicatedBlock = $elementsService->duplicateElement($block, [
Expand All @@ -226,7 +228,16 @@ public function saveValue(Field $field, ElementInterface $owner, bool $isNew)

$duplicatedBlock->setCollapsed($block->getCollapsed());
$duplicatedBlock->cacheCollapsed();
$duplicatedBlocks[] = $duplicatedBlock;
}

$duplicatedblockStructure = new BlockStructure();
$duplicatedblockStructure->fieldId = $field->id;
$duplicatedblockStructure->ownerId = $owner->id;
$duplicatedblockStructure->ownerSiteId = $ownerSiteId;

Neo::$plugin->blocks->saveStructure($duplicatedblockStructure);
Neo::$plugin->blocks->buildStructure($duplicatedBlocks, $duplicatedblockStructure);
}
}
else
Expand Down Expand Up @@ -329,6 +340,7 @@ private function _applyFieldTranslationSettings(int $ownerId, int $ownerSiteId,

if ($hasBlocks)
{
$blockStructure = Neo::$plugin->blocks->getStructure($fieldId, $ownerId);
$relatedElementFields = [];

foreach ($blocks as $block)
Expand Down Expand Up @@ -402,6 +414,9 @@ private function _applyFieldTranslationSettings(int $ownerId, int $ownerSiteId,
$block->ownerSiteId = $ownerSiteId;
$elementsService->saveElement($block, false);
}

$blockStructure->ownerSiteId = $ownerSiteId;
Neo::$plugin->blocks->saveStructure($blockStructure);
}
}
else
Expand Down

0 comments on commit eb7c20a

Please sign in to comment.