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

fields/merge command #15454

Merged
merged 5 commits into from
Jul 31, 2024
Merged

fields/merge command #15454

merged 5 commits into from
Jul 31, 2024

Conversation

brandonkelly
Copy link
Member

@brandonkelly brandonkelly commented Jul 31, 2024

Description

Adds a new fields/merge command, which accepts two custom field handles as arguments, and merges one into the other.

The command will do the following;

  1. Update any field layouts that contain instances of the outgoing field, and have those instances point to the persistent field instead.
  2. Remove the outgoing field.
  3. Generate and run a content migration, which calls afterMergeInto() on the outgoing field, and afterMergeFrom() on the persistent field, giving each field type a chance to react to the merge.

There’s a new MergeableFieldInterface, which field types must implement to opt into being mergeable. The interface defines canMergeInto() and canMergeFrom() methods, giving fields full control over which fields they can be merged with, from both ends of the equation. (By default, the base canMergeInto() and canMergeFrom() implementations will return true if both fields are of the same type, or their dbType() results are considered compatible with each other.)

All core field types except Table are mergeable, at least with other fields of the same type – including Matrix, Addresses, and relational fields.

The CLI output for a fields/merge command.

To propagate the change to other environments, just commit the modified project config YAML files, as well as the generated content migration, and then run craft up on other environments after pulling in the changes. Be sure to answer yes when prompted to run the pending content migration.

Related issues

Copy link

linear bot commented Jul 31, 2024

@brandonkelly brandonkelly merged commit 4b94ef3 into 5.3 Jul 31, 2024
@brandonkelly brandonkelly deleted the feature/cms-1309-fieldsmerge branch July 31, 2024 23:27
@yeboJoseph
Copy link

yeboJoseph commented Dec 9, 2024

Could we allow for the second argument to take an array or more than two arguments?
Ex: fields/merge heading [heading1, heading2, heading3, heading20] or fields/merge heading heading1 heading2 heading20
After updating from Craft 4 to 5, I want to merge certain fields into one. Ex: heading1, heading2, heading3, ...heading20. As of now, I'd have to run this command 20 times.
fields/auto-merge won't work in my instance has it merges all fields with the same settings.

@brandonkelly
Copy link
Member Author

(Responded from #16297.)

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

Successfully merging this pull request may close these issues.

2 participants