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

Copy field values from other sites #14056

Merged
merged 135 commits into from
Jan 11, 2025

Conversation

brianjhanson
Copy link
Contributor

@brianjhanson brianjhanson commented Dec 18, 2023

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.

A custom field’s action menu, with a “Copy value from site…” item

Plugin-supplied field types that want to add support for cross-site value copying will need to start implementing the new CrossSiteCopyableFieldInterface.

i-just and others added 30 commits November 30, 2022 17:25
# 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
@brandonkelly brandonkelly force-pushed the feature/cms-979-copy-field-values-from-other-sites branch from a366570 to 5ccacd8 Compare January 8, 2025 21:39
// 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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@brandonkelly brandonkelly force-pushed the feature/cms-979-copy-field-values-from-other-sites branch from 3286008 to d6f9669 Compare January 11, 2025 01:55
@brandonkelly brandonkelly merged commit defb577 into 5.6 Jan 11, 2025
8 checks passed
@brandonkelly brandonkelly deleted the feature/cms-979-copy-field-values-from-other-sites branch January 11, 2025 02:23
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.

5 participants