craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

[4.x]: Switching Entry Type Appends Fields From Other Entry Types To Field Layout When Adding Content #11746

Closed technikone closed 2 years ago

technikone commented 2 years ago

What happened?

Description

We created a section as a channel with three (3) entry types. The entry types use most of the same fields in their respective layouts. When a new entry is created and defaults to the first entry type in the drop menu, when a selection is made for a different entry type (no content has been entered), the field layout is refreshed and appends any differing fields to the bottom of the content entry form.

Steps to reproduce

  1. Create a section with 3 entry types that use many of the same fields (see attached entry layouts)
  2. Go to create a new entry in this section, do not enter any content
  3. Using the entry type drop menu, select a different entry type

Expected behavior

When a selection is made using the entry type drop menu, the content entry form should reflect the field layout created for the applicable entry type.

Actual behavior

The difference in fields among any two entry types is being appended to the bottom of the content entry form. What's even more interesting is that if you perform these same steps on a draft entry, the page reload prompt appears asking if you are sure you want to leave the page, and upon confirming, the page reloads with the new entry type field layout.

Current Field Layout For Entry Types:

Entry-Types

Example of Appended Field After Change In Entry Type

Entry-Types-Append

Craft CMS version

4.2.0.2

PHP version

8.0.8

Operating system and version

Darwin 21.6.0 (local development)

Database type and version

MySQL 5.7.34 (MAMP)

Image driver and version

GD 8.0.8

Installed plugins and versions

brandonkelly commented 2 years ago

Are you getting any JavaScript errors on the page?

technikone commented 2 years ago

No, no JavaScript errors are thrown. When simply interacting with the drop menu that holds the various entry types, the differing fields are appended to the bottom of the content entry form.

brandonkelly commented 2 years ago

Can you please send the following to support@craftcms.com?

Also please point us to the section where you’re seeing this.

brandonkelly commented 2 years ago

The culprit here is that the two entry types in question had several field layout tab/element UUIDs in common.

The whole point of field layout tabs/elements having UUIDs is so the element editor can know what’s currently visible, and what should be added/removed during autosaves, either due to field condition changes or switching the entry type. So it’s expected that the editor would get confused and become buggy if there are any duplicate UUIDs.

The most likely cause is human error, e.g. if an entry type was duplicated from another, by copying its project config data, but without assigning unique UUIDs to the field layout components.

We just added a new craft utils/fix-field-layout-uids command for the next release, which can be used to quickly resolve this.

To get it early, change your craftcms/cms constraint in composer.json to dev-develop as 4.2.1.1 and then run composer update. Then run the following command:

php craft utils/fix-field-layout-uids
technikone commented 2 years ago

Thanks for your help with this, it's much appreciated!

brandonkelly commented 2 years ago

Craft 4.2.2 is out now with that new command.