Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: Multi-instance fields with same handle show in different columns #15799

Closed
shifuma opened this issue Sep 27, 2024 · 1 comment
Closed
Assignees
Labels

Comments

@shifuma
Copy link

shifuma commented Sep 27, 2024

What happened?

Description

Matrix fields set to view as Element Index show multiple columns of the same field.

Steps to reproduce

  1. Create a Matrix field with two entry types
  2. Create a generic plain text field
  3. Add the plain text field to each entry type -> Settings > rename the handle to myTextField
  4. Add myTextField columns to index (there will be two of them)

Expected behavior

If a field has the same handle, the content will show in that column, even if it has been overwritten

Actual behavior

Fields with the same handle show in different columns because the handle has been changed

screenshot_2024_09_27 _12 57

screenshot_2024_09_27 _12 56

Craft CMS version

5.4.5

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@shifuma shifuma added the bug label Sep 27, 2024
@brandonkelly brandonkelly self-assigned this Sep 30, 2024
@brandonkelly
Copy link
Member

This is working as expected. Craft will only consolidate custom field columns across multiple entry types if their handle hasn’t been overridden. Otherwise the field will be identified by its field instance UUID, which is going to be unique for each entry type.

if ($layoutElement->handle === null) {
// The handle wasn't overridden, so combine it with any other instances (from other layouts)
// where the handle also wasn't overridden
$groupedFieldElements[$field->id][] = $layoutElement;
} else {
// The handle was overridden, so it gets its own table attribute
$attributes["fieldInstance:$layoutElement->uid"] = [
'label' => Craft::t('site', $field->name),
];
}

If you’d like each of these fields to share the same column, remove their overridden handles. If that’s not possible because the same field already exists in the layout with the default handle, you can create a new custom field to hold that data instead. You can then migrate the existing field values over to the new field using this command:

php craft resave/entries \
  --field <matrixFieldHandle> \
  --type <entryTypeHandle> \
  --set <newTextFieldHandle> \
  --to <oldTextFieldHandle>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants