Copy field values from other sites#14056
Merged
brandonkelly merged 135 commits into5.6from Jan 11, 2025
Merged
Conversation
# Conflicts: # src/controllers/ElementsController.php # src/web/assets/cp/dist/cp.js # src/web/assets/cp/dist/cp.js.map # src/web/assets/cp/dist/css/cp.css # src/web/assets/cp/dist/css/cp.css.map # src/web/assets/cp/src/js/ElementEditor.js
a366570 to
5ccacd8
Compare
brandonkelly
reviewed
Jan 8, 2025
brandonkelly
reviewed
Jan 8, 2025
brandonkelly
reviewed
Jan 8, 2025
| // if we're copying a single field (so we have the hud, not the modal) | ||
| if (this.copyHud) { | ||
| // check if the field is classed as nested | ||
| return Garnish.hasAttr(this.copyHud.$trigger, 'data-nested'); |
Member
There was a problem hiding this comment.
Since non-NEM fields are also creating drafts, could we just remove this method and assume that every time we’re copying field values, a draft should be created first?
If so we can also remove craft\fieldlayoutelements\BaseField::isNested().
Contributor
There was a problem hiding this comment.
That’s needed to allow copying fields inside of a matrix field that’s set to editable blocks mode to work.
Replication steps:
- have at least 2 sites set up
- create a matrix field in editable blocks mode with the propagation method set to “all”
- the matrix field should have an entry type that has, e.g. plain text field set to be translatable
- create a section that’s enabled for both sites; its entry type should use the matrix field we just created
- create an entry in that section, add a block to the matrix field, fill out the plain text field, fully save the entry
- edit the entry in the second site, change the plain text field inside the matrix field so that it’s clear it’s from the other site & fully save
- in either site, edit the entry and copy the plain text field inside the matrix field from the other site
with the code you asked about, it works as expected; without it, it does not
Not possible to copy everything in a way that's consistent with individual field value copying, without dropping support for Matrix (at which point, what's the point?)
3286008 to
d6f9669
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuation of #12436 but instead of handling the copy server-side, the controller will return fragments of HTML that we use to replace fields and immediately save a draft. This simplifies the logic a bit as we can rely on existing "Save Draft" processes to save the values.
Description
Adds a new “Copy value from site…” action to translatable fields’ action menus on element edit pages, making it possible to copy the field value from another site over to the current site.
Plugin-supplied field types that want to add support for cross-site value copying will need to start implementing the new
CrossSiteCopyableFieldInterface.