diff --git a/CHANGELOG.md b/CHANGELOG.md index f021ce6..ec17254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## Unreleased +## 3.3.3 - 2019-02-22 + +### Fixed +- Fixed a couple more cases where the Matrix blocktype might not exist for some reason ([#52](https://github.com/angell-co/Spoon/issues/52)) + + ## 3.3.2 - 2019-02-21 ### Changed diff --git a/src/controllers/BlockTypesController.php b/src/controllers/BlockTypesController.php index cbcd958..918757f 100644 --- a/src/controllers/BlockTypesController.php +++ b/src/controllers/BlockTypesController.php @@ -65,43 +65,45 @@ public function actionIndex($variables = []) $superTableBlockTypeId = Db::idByUid('{{%supertableblocktypes}}', $parts[1]); - /** @var \verbb\supertable\models\SuperTableBlockTypeModel $superTableBlockType */ - $superTableBlockType = $superTableService->getBlockTypeById($superTableBlockTypeId); - - /** @var \verbb\supertable\fields\SuperTableField $superTableField */ - $superTableField = \Craft::$app->fields->getFieldById($superTableBlockType->fieldId); - - $variables['superTableFields'][$matrixField->context] = [ - 'kind' => 'Super Table', - 'field' => $superTableField, - 'child' => false - ]; - - // If the context of _this_ field is inside a Matrix block ... then we need to do more inception - if (strpos($superTableField->context, 'matrixBlockType') === 0) { - $nestedParts = explode(':', $superTableField->context); - if (isset($nestedParts[1])) { - - $matrixBlockTypeId = Db::idByUid('{{%matrixblocktypes}}', $nestedParts[1]); - - /** @var craft\models\MatrixBlockType $matrixBlockType */ - $matrixBlockType = \Craft::$app->matrix->getBlockTypeById($matrixBlockTypeId); - - /** @var craft\fields\Matrix $globalField */ - $globalField = \Craft::$app->fields->getFieldById($matrixBlockType->fieldId); - - $variables['superTableFields'][$matrixField->context] = [ - 'kind' => 'Matrix', - 'field' => $globalField, - 'child' => [ - 'kind' => 'Super Table', - 'field' => $superTableField - ] - ]; - + if ($superTableBlockTypeId) { + /** @var \verbb\supertable\models\SuperTableBlockTypeModel $superTableBlockType */ + $superTableBlockType = $superTableService->getBlockTypeById($superTableBlockTypeId); + + /** @var \verbb\supertable\fields\SuperTableField $superTableField */ + $superTableField = \Craft::$app->fields->getFieldById($superTableBlockType->fieldId); + + $variables['superTableFields'][$matrixField->context] = [ + 'kind' => 'Super Table', + 'field' => $superTableField, + 'child' => false + ]; + + // If the context of _this_ field is inside a Matrix block ... then we need to do more inception + if (strpos($superTableField->context, 'matrixBlockType') === 0) { + $nestedParts = explode(':', $superTableField->context); + if (isset($nestedParts[1])) { + + $matrixBlockTypeId = Db::idByUid('{{%matrixblocktypes}}', $nestedParts[1]); + + if ($matrixBlockTypeId) { + /** @var craft\models\MatrixBlockType $matrixBlockType */ + $matrixBlockType = \Craft::$app->matrix->getBlockTypeById($matrixBlockTypeId); + + /** @var craft\fields\Matrix $globalField */ + $globalField = \Craft::$app->fields->getFieldById($matrixBlockType->fieldId); + + $variables['superTableFields'][$matrixField->context] = [ + 'kind' => 'Matrix', + 'field' => $globalField, + 'child' => [ + 'kind' => 'Super Table', + 'field' => $superTableField + ] + ]; + } + } } } - } } }