diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bb34a6..ba4888b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/services/BlockTypes.php b/src/services/BlockTypes.php index db207ab..ecac7ce 100644 --- a/src/services/BlockTypes.php +++ b/src/services/BlockTypes.php @@ -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();