Skip to content

Commit

Permalink
Merge pull request #93 from qrazi/handle_block_type_changes_defensively
Browse files Browse the repository at this point in the history
Fixed an issue with the order of synchronization
  • Loading branch information
joshangell authored Jul 30, 2020
2 parents 06637c8 + b12c03d commit 5331521
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## Unreleased

### Fixed
- Fixed an issue with the order of synchronization of matrix block types and spoon block types ([#90](https://github.com/angell-co/Spoon/issues/90))
- Fixed an issue with newer versions of Super Table ([#98](https://github.com/angell-co/Spoon/issues/98))
- Fixed an error that could occur when matrix fields don’t return properly by ID ([#92](https://github.com/angell-co/Spoon/issues/92))

Expand Down
16 changes: 12 additions & 4 deletions src/services/BlockTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,19 @@ public function handleChangedBlockType(ConfigEvent $event)
$uid = $event->tokenMatches[0];
$data = $event->newValue;

$fieldUid = $data['field'];
$fieldId = Db::idByUid(Table::FIELDS, $fieldUid);
// Make sure the field has been synced
$fieldId = Db::idByUid(Table::FIELDS, $data['field']);
if ($fieldId === null) {
Craft::$app->getProjectConfig()->defer($event, [$this, __FUNCTION__]);
return;
}

$matrixBlockTypeUid = $data['matrixBlockType'];
$matrixBlockTypeId = Db::idByUid(Table::MATRIXBLOCKTYPES, $matrixBlockTypeUid);
// Make sure the matrix block type has been synced
$matrixBlockTypeId = Db::idByUid(Table::MATRIXBLOCKTYPES, $data['matrixBlockType']);
if ($matrixBlockTypeId === null) {
Craft::$app->getProjectConfig()->defer($event, [$this, __FUNCTION__]);
return;
}

// Make sure fields and sites are processed
ProjectConfigHelper::ensureAllSitesProcessed();
Expand Down

0 comments on commit 5331521

Please sign in to comment.