Skip to content

Commit

Permalink
Fixed #12459
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Dec 15, 2022
1 parent 7f5e2cb commit 2947da1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft CMS 4

## Unreleased

- Fixed a bug where deleting a field layout tab could result in duplicated tabs. ([#12459](https://github.com/craftcms/cms/issues/12459))

## 4.3.5 - 2022-12-13

- Fixed a bug where entry tab contents could remain visible when switching to other tabs, after changing the entry type.
Expand Down
23 changes: 23 additions & 0 deletions src/models/FieldLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ public function setTabs(array $tabs): void
$this->_tabs = [];

$index = 0;
$elementUids = [];

foreach ($tabs as $tab) {
if (is_array($tab)) {
Expand All @@ -315,6 +316,28 @@ public function setTabs(array $tabs): void
} else {
$tab->setLayout($this);
}

// Ensure there aren't any layout element UUID conflicts
$layoutElements = $tab->getElements();
$filteredLayoutElements = array_filter($layoutElements, function(FieldLayoutElement $layoutElement) use (&$elementUids) {
if (!isset($layoutElement->uid)) {
return true;
}
if (isset($elementUids[$layoutElement->uid])) {
return false;
}
$elementUids[$layoutElement->uid] = true;
return true;
});

if (empty($filteredLayoutElements)) {
continue;
}

if (count($filteredLayoutElements) !== count($layoutElements)) {
$tab->setElements($filteredLayoutElements);
}

$tab->sortOrder = ++$index;
$this->_tabs[] = $tab;
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions src/web/assets/cp/src/js/FieldLayoutDesigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Craft.FieldLayoutDesigner.Tab = Garnish.Base.extend({
uid: null,
$container: null,
slideout: null,
destroyed: false,

init: function (designer, $container) {
this.designer = designer;
Expand Down Expand Up @@ -485,6 +486,10 @@ Craft.FieldLayoutDesigner.Tab = Garnish.Base.extend({
},

set config(config) {
if (this.destroyed) {
return;
}

// Is the name changing?
if (config.name && config.name !== this.config.name) {
this.$container.find('.tabs .tab span').text(config.name);
Expand All @@ -505,13 +510,21 @@ Craft.FieldLayoutDesigner.Tab = Garnish.Base.extend({
},

updateConfig: function (callback) {
if (this.destroyed) {
return;
}

const config = callback(this.config);
if (config !== false) {
this.config = config;
}
},

updatePositionInConfig: function () {
if (this.destroyed) {
return;
}

this.designer.updateConfig((config) => {
const tabConfig = this.config;
const oldIndex = this.index;
Expand All @@ -528,6 +541,12 @@ Craft.FieldLayoutDesigner.Tab = Garnish.Base.extend({
},

destroy: function () {
if (this.destroyed) {
return;
}

this.destroyed = true;

this.designer.updateConfig((config) => {
const index = this.index;
if (index === -1) {
Expand Down

0 comments on commit 2947da1

Please sign in to comment.