Skip to content

Commit

Permalink
Merge branch 'release/3.5.2'
Browse files Browse the repository at this point in the history
* release/3.5.2:
  Changelog for 3.5.2
  Added note to changelog about updating to 3.5.x from pre 3.4.0
  Fixed project config helper yet again.
  Fixes an issue with removing field layouts from current block type configurations.
  Drop project config data on uninstall.
  Added fix in project config helper to deal with upgrading from older versions.
  • Loading branch information
joshangell committed Feb 7, 2020
2 parents c54f6e8 + ba5bd66 commit 06ab92c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 27 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## Unreleased

## 3.5.2 - 2020-02-07

### Changed
- Spoon-specific project config data is now wiped on uninstall ([#85](https://github.com/angell-co/Spoon/issues/85))

### Fixed
- Fixed an issue with updating to 3.5.x from 3.3.x ([#89](https://github.com/angell-co/Spoon/issues/89))
- Fixed an issue with removing field layouts from current block type configurations ([#84](https://github.com/angell-co/Spoon/issues/84))


## 3.5.1 - 2020-02-05

### Fixed
Expand All @@ -15,6 +25,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## 3.5.0 - 2020-02-05

> {note} Before updating to 3.5.0 or greater it is a good idea to update to 3.4.3 first.
### Fixed
- Fixed things not working with Craft 3.4 ([#79](https://github.com/angell-co/Spoon/issues/79))
- Fixed an issue with block type configurations not keeping their order when deployed to another environment via project config ([#80](https://github.com/angell-co/Spoon/issues/80))
Expand Down
12 changes: 12 additions & 0 deletions src/Spoon.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,16 @@ protected function createSettingsModel()
return new Settings();
}

/**
* @inheritdoc
*/
protected function afterUninstall()
{
// After uninstall drop project config keys
$projectConfig = Craft::$app->getProjectConfig();
$projectConfig->muteEvents = true;
$projectConfig->remove(BlockTypes::CONFIG_BLOCKTYPE_KEY);
$projectConfig->muteEvents = false;
}

}
16 changes: 11 additions & 5 deletions src/controllers/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,11 @@ public function actionSaveFieldLayout()
$spoonedBlockTypeId = Craft::$app->getRequest()->getParam('spoonedBlockTypeId');
$blockTypeFieldLayouts = Craft::$app->getRequest()->getParam('blockTypeFieldLayouts');

if ($spoonedBlockTypeId)
{
if ($spoonedBlockTypeId) {
if (!$spoonedBlockType = Spoon::$plugin->blockTypes->getById($spoonedBlockTypeId)) {
return false;
}
} else
{
} else {
return false;
}

Expand All @@ -180,12 +178,20 @@ public function actionSaveFieldLayout()

// We don’t have a new field layout, so remove the old one if there is one
$oldFieldLayoutId = $spoonedBlockType->fieldLayoutId;
if (!Craft::$app->fields->deleteLayoutById($oldFieldLayoutId)) {
return $this->asJson([
'success' => false
]);
}

// Also null the col on our block type row
$spoonedBlockType->fieldLayoutId = null;
if (!Spoon::$plugin->blockTypes->save($spoonedBlockType) || !Craft::$app->fields->deleteLayoutById($oldFieldLayoutId)) {
if (!Spoon::$plugin->blockTypes->save($spoonedBlockType)) {
return $this->asJson([
'success' => false
]);
}

}

return $this->asJson([
Expand Down
39 changes: 24 additions & 15 deletions src/helpers/ProjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,32 @@ class ProjectConfig
*/
public static function rebuildProjectConfig(): array
{
$projectConfig = Craft::$app->getProjectConfig();
$schemaVersion = $projectConfig->get('plugins.spoon.schemaVersion', true);
$oldSchema = version_compare($schemaVersion, '3.4.0', '<');

$fields = Craft::$app->getFields();
$configData = [];

$selectArray = [
'b.uid',
'b.fieldId',
'b.matrixBlockTypeId',
'b.fieldLayoutId',
'b.groupName',
'b.context',
'b.uid',
'f.uid AS fieldUid',
'mbt.uid AS matrixBlockUid',
];

if (!$oldSchema) {
$selectArray[] = 'b.groupSortOrder';
$selectArray[] = 'b.sortOrder';
}

$blockTypes = (new Query())
->select([
'b.uid',
'b.fieldId',
'b.matrixBlockTypeId',
'b.fieldLayoutId',
'b.groupName',
'b.context',
'b.groupSortOrder',
'b.sortOrder',
'b.uid',
'f.uid AS fieldUid',
'mbt.uid AS matrixBlockUid',
])
->select($selectArray)
->from(['{{%spoon_blocktypes}} b'])
->innerJoin('{{%fields}} f', '[[b.fieldId]] = [[f.id]]')
->innerJoin('{{%matrixblocktypes}} mbt', '[[b.matrixBlockTypeId]] = [[mbt.id]]')
Expand All @@ -41,8 +50,8 @@ public static function rebuildProjectConfig(): array
$data = [
'groupName' => $blockType['groupName'],
'context' => $blockType['context'],
'groupSortOrder' => $blockType['groupSortOrder'],
'sortOrder' => $blockType['sortOrder'],
'groupSortOrder' => $oldSchema ? null : $blockType['groupSortOrder'],
'sortOrder' => $oldSchema ? null : $blockType['sortOrder'],
'field' => $blockType['fieldUid'],
'matrixBlockType' => $blockType['matrixBlockUid'],
];
Expand Down
12 changes: 7 additions & 5 deletions src/services/BlockTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,13 @@ private function _populateBlockTypeFromRecord(BlockTypeRecord $blockTypeRecord)
$blockType->matrixBlockType = $blockType->getBlockType();

// Save the field layout content on to our model
$layout = $blockType->getFieldLayout();
$blockType->fieldLayoutModel = [
'tabs' => $layout->getTabs(),
'fields' => $layout->getFields()
];
if ($blockType->fieldLayoutId) {
$layout = $blockType->getFieldLayout();
$blockType->fieldLayoutModel = [
'tabs' => $layout->getTabs(),
'fields' => $layout->getFields()
];
}

return $blockType;
}
Expand Down
6 changes: 4 additions & 2 deletions src/services/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,10 @@ public function fieldManipulator($context, $versioned = false)
$translations[] = $spoonedBlockType->groupName;
$translations[] = $spoonedBlockType->matrixBlockType->name;

foreach ($spoonedBlockType->fieldLayoutModel['tabs'] as $tab) {
$translations[] = $tab->name;
if ($spoonedBlockType->fieldLayoutModel) {
foreach ($spoonedBlockType->fieldLayoutModel['tabs'] as $tab) {
$translations[] = $tab->name;
}
}

}
Expand Down

0 comments on commit 06ab92c

Please sign in to comment.