Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Oct 3, 2018
1 parent a2e190c commit cb69ddf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/services/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ public function saveField(MatrixField $field, ElementInterface $owner)
$blocks = $query->all();
}

$elementsService = Craft::$app->getElements();

$transaction = Craft::$app->getDb()->beginTransaction();
try {
// If this is a preexisting element, make sure that the blocks for this field/owner respect the field's translation setting
Expand All @@ -647,7 +649,6 @@ public function saveField(MatrixField $field, ElementInterface $owner)
$newQuery->ownerId = $owner->id;
if (!$newQuery->exists()) {
// Duplicate the blocks for the new owner
$elementsService = Craft::$app->getElements();
foreach ($blocks as $block) {
$elementsService->duplicateElement($block, [
'ownerId' => $owner->id,
Expand All @@ -667,7 +668,7 @@ public function saveField(MatrixField $field, ElementInterface $owner)
$block->ownerSiteId = ($field->localizeBlocks ? $owner->siteId : null);
$block->propagating = $owner->propagating;

Craft::$app->getElements()->saveElement($block, false, $propagate);
$elementsService->saveElement($block, false, $propagate);

$blockIds[] = $block->id;

Expand Down

0 comments on commit cb69ddf

Please sign in to comment.