Skip to content

Commit

Permalink
Delete empty field groups on import with force
Browse files Browse the repository at this point in the history
  • Loading branch information
bvangennep committed Nov 18, 2018
1 parent fa30b95 commit 3489dc4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### 4.0.18
### Added
- Delete empty field groups on import with force
### Fixed
- Fixed user field sources not being exported

Expand Down
15 changes: 15 additions & 0 deletions src/DataTypes/FieldDataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,20 @@ public function getRecords(): array
public function afterImport()
{
Craft::$app->fields->updateFieldVersion();
if (Schematic::$force) {
$this->clearEmptyGroups();
}
}

/**
* Clear empty field groups
*/
private function clearEmptyGroups()
{
foreach (Craft::$app->fields->getAllGroups() as $group) {
if (count($group->getFields()) == 0) {
Craft::$app->fields->deleteGroup($group);
}
}
}
}

0 comments on commit 3489dc4

Please sign in to comment.