Skip to content

Commit

Permalink
Merge branch 'release/3.3.3'
Browse files Browse the repository at this point in the history
* release/3.3.3:
  Changelog for 3.3.3
  Check we got a block type ID before proceeding in a couple of places
  • Loading branch information
joshangell committed Feb 22, 2019
2 parents a960ce9 + 6e337bb commit e82f5bb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 37 additions & 35 deletions src/controllers/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
];
}
}
}
}

}
}
}
Expand Down

0 comments on commit e82f5bb

Please sign in to comment.