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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
ccaa6f3
POC for copying fields over (WIP)
i-just Nov 30, 2022
e51cac0
show notifications
i-just Dec 1, 2022
7dc40cf
copy only top level fields
i-just Dec 1, 2022
3f2ce0c
site select hooked up
i-just Dec 1, 2022
bfe9ff4
additional safeguards; adjust for title, slug; bug fixes
i-just Dec 2, 2022
5784fa7
Merge branch 'develop' into feature/979-copy-field-values-from-other-…
i-just Dec 2, 2022
2456d85
Merge branch '4.4' into feature/979-copy-field-values-from-other-sites
i-just Dec 2, 2022
74b215e
bug fix
i-just Dec 2, 2022
870a6a5
copyable field interface added
i-just Dec 7, 2022
d922efe
copy all element content; improve checks
i-just Dec 7, 2022
f72bddc
bug fix and refactoring
i-just Dec 8, 2022
d33c140
Merge branch 'develop' into feature/979-copy-field-values-v1
i-just Dec 9, 2022
a5229ab
disclosure menu for selecting site to copy from
i-just Dec 9, 2022
d8f3fae
styling improvement
i-just Dec 12, 2022
97910e2
Merge branch '4.4' into feature/979-copy-field-values-v1
brandonkelly Jan 11, 2023
7db371e
Merge branch '4.4' into feature/979-copy-field-values-v1
i-just Feb 20, 2023
6436864
make translatable icon accessible via keyboard
i-just Feb 20, 2023
53454b8
Merge remote-tracking branch 'origin/4.5' into feature/979-copy-field…
i-just Apr 12, 2023
06575f5
Merge branch '4.5' into feature/979-copy-field-values-v1
i-just Jul 20, 2023
c85950a
UI amends
i-just Jul 20, 2023
b83ac89
Merge branch '5.0' into feature/979-copy-field-values-v1
i-just Oct 13, 2023
aa6caac
support for multi-instance fields
i-just Oct 13, 2023
939654f
WIP - close the hud and reload the page
i-just Oct 13, 2023
4512263
bug fixes
i-just Oct 16, 2023
761924f
Merge branch '5.0' into feature/979-copy-field-values-v1
i-just Oct 16, 2023
38aaf79
tweaks
i-just Oct 17, 2023
fee2823
Merge branch '5.0' of github.com:craftcms/cms into feature/979-copy-f…
brianjhanson Dec 11, 2023
71397bc
Merge branch '5.0' into feature/979-copy-field-values-v1
i-just Dec 12, 2023
282dc8b
copyable country field
i-just Dec 12, 2023
5fd7d2f
improved slideout handling + notices
i-just Dec 12, 2023
52b1191
Merge branch '5.0' of github.com:craftcms/cms into feature/cms-979-co…
brianjhanson Dec 18, 2023
bc630e1
Merge commit '5fd7d2f5a3082b013b7cab7693bb95c9c584ca3b' of github.com…
brianjhanson Dec 18, 2023
3c2a490
Send back HTML when updating fields
brianjhanson Dec 19, 2023
278b089
Move field translation icon into button
brianjhanson Dec 19, 2023
e07ac12
Fix bug coping reserved handles
brianjhanson Dec 19, 2023
7252f3a
Convert copy attribute to web component
brianjhanson Dec 19, 2023
e44182f
Convert copy attribute to web component
brianjhanson Dec 19, 2023
48350bb
Better HUD hiding
brianjhanson Dec 19, 2023
7c9a0d5
Add `data-layout-element` attribute
brianjhanson Dec 19, 2023
1a7ca0e
Give up on Matrix for the moment
brianjhanson Dec 19, 2023
32dc390
More explicit namespace setting
brianjhanson Dec 19, 2023
0d95d47
Use event delegation
brianjhanson Dec 19, 2023
7d42d4e
Copy Matrix fields
brianjhanson Dec 20, 2023
2a8c259
Build
brianjhanson Dec 20, 2023
ac26858
Merge branch '5.5' of github.com:craftcms/cms into feature/cms-979-co…
brianjhanson Sep 24, 2024
cc30dec
fix saving issue that occurred after merge
i-just Sep 25, 2024
8a67e08
comments, since tags and remove repetition
i-just Sep 25, 2024
b6d1786
copyable support for Icon and Link fields
i-just Sep 25, 2024
6e434a6
cleanup
i-just Sep 25, 2024
1df74bb
allow copying for elements that don't support drafts
i-just Sep 25, 2024
3bfb7e0
better way to handle not custom fields
i-just Sep 25, 2024
4c706f2
native alt field is translatable, so allow copying
i-just Sep 25, 2024
d6f3d84
namespace inputs differently
i-just Sep 25, 2024
c7de1e7
build
i-just Sep 25, 2024
7dba512
Wrap translation icons in `craft-tooltip`s
brianjhanson Sep 26, 2024
a24c1f7
Fix z-index
brianjhanson Sep 26, 2024
f6a57f0
Add ability to trigger tooltip from outside element
brianjhanson Sep 26, 2024
c9ad2ff
Remove `aria-label` reference
brianjhanson Sep 26, 2024
14d1e38
Minor update
brianjhanson Sep 26, 2024
426d342
Better auto-updating
brianjhanson Sep 26, 2024
95e71d1
Actually remove event listner
brianjhanson Sep 26, 2024
0dc8ff2
permissions & static context
i-just Sep 27, 2024
e3fddac
don't show copy action in chips/cards
i-just Sep 27, 2024
cad0f64
build
i-just Sep 27, 2024
583a039
Merge branch '5.5' into feature/cms-979-copy-field-values-from-other-…
i-just Sep 27, 2024
6d91d54
disallow copying for fields in matrix "blocks"
i-just Sep 27, 2024
d586e72
Remove need to `.bind(this)`
brianjhanson Sep 27, 2024
027d36e
Increase delay a bit
brianjhanson Sep 27, 2024
7f99d21
allow copying of fields in matrix "block" but only when opened as a s…
i-just Oct 1, 2024
c823223
Copy individual inline-matrix fields
brianjhanson Oct 3, 2024
9d24f6b
Remove copy blocking
brianjhanson Oct 3, 2024
e1c041c
Cleanup console.log
brianjhanson Oct 3, 2024
b0758a1
Merge branch '5.5' into feature/cms-979-copy-field-values-from-other-…
i-just Oct 7, 2024
26cb281
namespace adjustment - fixes modified field issue (and others)
i-just Oct 7, 2024
dbe0c90
bug fix - copying matrix field content when the matrix is "translatable"
i-just Oct 7, 2024
536123a
build
i-just Oct 7, 2024
fde01db
Revert "namespace adjustment - fixes modified field issue (and others)"
i-just Oct 7, 2024
b16b8bb
marry matrix "blocks" and "entries" copying
i-just Oct 7, 2024
b8c9c6d
build
i-just Oct 7, 2024
7af7fb2
empty value is still a value
i-just Oct 10, 2024
fb60503
ensure draft before copying the entire element too
i-just Oct 10, 2024
ef78914
build
i-just Oct 10, 2024
ab4dd6a
Merge branch '5.5' into feature/cms-979-copy-field-values-from-other-…
i-just Oct 10, 2024
dea7ea6
back to Brian's namespacing, but with a twist
i-just Oct 11, 2024
bb3fda6
build
i-just Oct 11, 2024
4435084
more namespacing changes
i-just Oct 11, 2024
43e98e3
Merge branch '5.5' into feature/cms-979-copy-field-values-from-other-…
i-just Oct 17, 2024
ac4dccf
Merge branch '5.5' into feature/cms-979-copy-field-values-from-other-…
i-just Oct 23, 2024
796f459
fixes for copy all accessibility issues
i-just Oct 23, 2024
9b498d8
change aria-role to role
i-just Oct 23, 2024
681948c
trigger field copy dialogue via keyboard
i-just Oct 23, 2024
77b20a6
build
i-just Oct 23, 2024
28fabc4
only create provisional draft first if we're about to copy field with…
i-just Oct 23, 2024
79a633f
build
i-just Oct 23, 2024
464f6ed
announce loading/complete for filter hud
i-just Oct 24, 2024
f0580af
Move copy button to right side of field
brianjhanson Oct 24, 2024
78741c6
Handle `aria-expanded` for HUD
brianjhanson Oct 24, 2024
705f088
Add modal heading
brianjhanson Oct 24, 2024
cc1c6de
Add toggle via click
brianjhanson Oct 24, 2024
7a44349
Remove self-managed
brianjhanson Oct 24, 2024
2c65a82
Meaningful label
brianjhanson Oct 24, 2024
d99cbb5
Build
brianjhanson Oct 25, 2024
a7437b5
accessibility amends round 2
i-just Oct 25, 2024
b791847
don't show the icon if there's no sites to copy from & performance
i-just Oct 25, 2024
2d92601
Merge branch '5.5' into feature/cms-979-copy-field-values-from-other-…
i-just Oct 25, 2024
6b25bff
Keep tooltip open when hovering
brianjhanson Nov 1, 2024
c2b50d6
Merge branch '5.5' of github.com:craftcms/cms into feature/cms-979-co…
brianjhanson Nov 4, 2024
894ce7a
Merge branch '5.6' into feature/cms-979-copy-field-values-from-other-…
i-just Jan 6, 2025
80e9d44
prettier
i-just Jan 6, 2025
e839b6d
Fix tooltip placement
brianjhanson Jan 6, 2025
74f354e
build
i-just Jan 7, 2025
5ccacd8
Merge branch '5.6' into feature/cms-979-copy-field-values-from-other-…
brandonkelly Jan 8, 2025
f9c0b83
Merge branch '5.6' into feature/cms-979-copy-field-values-from-other-…
brandonkelly Jan 8, 2025
e39a0a1
Clearer
brandonkelly Jan 8, 2025
25964b4
Update `@since` tags
brandonkelly Jan 8, 2025
f306a93
Remove `copying` from element arrays
brandonkelly Jan 8, 2025
c6ac3c0
remove code that's no longer used
i-just Jan 9, 2025
20864ef
build
i-just Jan 9, 2025
d765329
Merge branch '5.6' into feature/cms-979-copy-field-values-from-other-…
brandonkelly Jan 9, 2025
dffc536
Use StringHelper::removeRight()
brandonkelly Jan 9, 2025
ad517d8
Merge branch '5.6' into feature/cms-979-copy-field-values-from-other-…
brandonkelly Jan 10, 2025
f98498d
Cleanup
brandonkelly Jan 10, 2025
e90d4cd
Drop the copy action, cleanup & stability improvements
brandonkelly Jan 10, 2025
ff0576c
More cleanup
brandonkelly Jan 10, 2025
a7476ff
Merge branch '5.6' into feature/cms-979-copy-field-values-from-other-…
brandonkelly Jan 10, 2025
b5f8129
Move the copy trigger into the field action menu
brandonkelly Jan 10, 2025
ae46cee
Fix hover issue
brianjhanson Jan 10, 2025
827f8db
Build
brianjhanson Jan 10, 2025
a023c94
Fix PHPStan issue
brandonkelly Jan 11, 2025
209675f
Cleanup
brandonkelly Jan 11, 2025
6a115a7
Merge branch '5.6' into feature/cms-979-copy-field-values-from-other-…
brandonkelly Jan 11, 2025
e3718ce
Cleanup
brandonkelly Jan 11, 2025
69a0b63
Unused import
brandonkelly Jan 11, 2025
d6f9669
Release notes
brandonkelly Jan 11, 2025
b317726
Prettier
brandonkelly Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release notes for Craft CMS 5.6 (WIP)

### Content Management
- It’s now possible to copy custom field values from other sites. ([#14056](https://github.com/craftcms/cms/pull/14056))
- “Related To”, “Not Related To”, “Author”, and relational field condition rules now allow multiple elements to be specified. ([#16121](https://github.com/craftcms/cms/discussions/16121))
- Improved the styling of inline code fragments. ([#16141](https://github.com/craftcms/cms/pull/16141))
- Improved the styling of attribute previews in card view. ([#16324](https://github.com/craftcms/cms/pull/16324))
Expand All @@ -13,7 +14,7 @@
- Entry indexes now only show table column options and sort options for custom fields associated with the selected sections/entry types within custom entry sources’ conditions.
- Structure views are now available to element indexes on mobile browsers. ([#16190](https://github.com/craftcms/cms/discussions/16190))
- Datepickers now include a dropdown menu for selecting the year. ([#16376](https://github.com/craftcms/cms/pull/16376))
- Custom fields within element edit pages can now have action menus with “Edit field” and “Copy field handle” items. ([#16415](https://github.com/craftcms/cms/pull/16415))
- Custom fields within element edit pages can now have action menus with “Copy value from site…”, “Edit field” and “Copy field handle” items. ([#16415](https://github.com/craftcms/cms/pull/16415), [#14056](https://github.com/craftcms/cms/pull/14056))
- Heads-up displays now reposition themselves on window scroll.

### Accessibility
Expand All @@ -24,6 +25,7 @@
- Improved the accessibility of action menus on the Plugins index page.
- Improved the accessibility of “More” and “Advanced” toggle triggers. ([#16293]](https://github.com/craftcms/cms/pull/16293))
- Improved the accessibility of the Craft Support widget. ([#16293]](https://github.com/craftcms/cms/pull/16293))
- Improved the accessibility of field translatable indicators and tooltips.

### Administration
- Added the “Affiliated Site” native user field. ([#16174](https://github.com/craftcms/cms/pull/16174))
Expand Down Expand Up @@ -121,6 +123,10 @@
- Added `craft\web\User::setImpersonatorId()`.
- Added `craft\web\View::setTwig()`.
- Added `craft\web\twig\variables\Cp::EVENT_REGISTER_READ_ONLY_CP_SETTINGS`. ([#16265](https://github.com/craftcms/cms/pull/16265))
- Added `craft\base\CrossSiteCopyableFieldInterface`. ([#14056](https://github.com/craftcms/cms/pull/14056))
- Added `craft\base\ElementInterface::getIsCrossSiteCopyable()`. ([#14056](https://github.com/craftcms/cms/pull/14056))
- Added `craft\base\Field::copyCrossSiteValue()`. ([#14056](https://github.com/craftcms/cms/pull/14056))
- Added `craft\fieldlayoutelements\BaseField::isCrossSiteCopyable()`.
- `GuzzleHttp\Client` is now instantiated via `Craft::createObject()`. ([#16366](https://github.com/craftcms/cms/pull/16366))
- `craft\elements\NestedElementManager::getIndexHtml()` now supports passing `defaultSort` in the `$config` array. ([#16236](https://github.com/craftcms/cms/discussions/16236))
- `craft\elements\conditions\entries\MatrixFieldConditionRule` is now an alias of `FieldConditionRule`.
Expand Down
4 changes: 2 additions & 2 deletions packages/craftcms-sass/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ $menuBorderRadius: $mediumBorderRadius;
sans-serif;
}

@mixin fixed-width-font {
@mixin fixed-width-font($size: 0.9em) {
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier,
monospace;
font-size: 0.9em !important;
font-size: $size !important;
}

@function toRem($values...) {
Expand Down
10 changes: 10 additions & 0 deletions packages/craftcms-webpack/Craft.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@ interface ProgressBarInterface {
showProgressBar(): void;
}

type Site = {
handle: string;
id: number;
name: string;
uid: string;
};

// Declare existing variables, mock the things we'll use.
declare var Craft: {
csrfTokenName?: string;
csrfTokenValue?: string;
ProgressBar: ProgressBarInterface;
t(category: string, message: string, params?: object): string;
sendActionRequest(method: string, action: string, options?: object): Promise;
initUiElements($container: JQuery): void;
expandPostArray(arr: object): any;
escapeHtml(str: string);
sites: Site[];
Preview: any;
cp: any;
};
Expand Down
26 changes: 26 additions & 0 deletions src/base/CrossSiteCopyableFieldInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\base;

/**
* CrossSiteCopyableFieldInterface defines the common interface to be implemented by field classes
* that wish to support copying their values between sites in a multisite installation.
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 5.6.0
*/
interface CrossSiteCopyableFieldInterface
{
/**
* Copies the field’s value from one site to another.
*
* @param ElementInterface $from
* @param ElementInterface $to
*/
public function copyCrossSiteValue(ElementInterface $from, ElementInterface $to): void;
}
24 changes: 24 additions & 0 deletions src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,12 @@ private static function _indexOrderByColumns(
*/
private $_serializeFields = false;

/**
* @var bool
* @see getIsCrossSiteCopyable()
*/
private bool $_isCrossSiteCopyable;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -5485,6 +5491,24 @@ public function getCurrentRevision(): ?ElementInterface
return $this->_currentRevision ?: null;
}

/**
* @inheritdoc
*/
public function getIsCrossSiteCopyable(): bool
{
if (!isset($this->_isCrossSiteCopyable)) {
$this->_isCrossSiteCopyable = (
Craft::$app->getIsMultiSite() &&
// check if user can edit this element in other sites
count(ElementHelper::editableSiteIdsForElement($this)) > 1 &&
// also check if the element exists in other sites
!empty(array_diff(array_keys(ElementHelper::siteStatusesForElement($this, true)), [$this->siteId]))
);
}

return $this->_isCrossSiteCopyable;
}

// Indexes, etc.
// -------------------------------------------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions src/base/ElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,16 @@ public function setRevisionNotes(?string $notes): void;
*/
public function getCurrentRevision(): ?self;

/**
* Return if the element is copyable between sites.
* Checks if it's a multisite installation, if user can edit the element in other sites,
* and if the element actually exists in other sites.
*
* @return bool
* @since 5.6.0
*/
public function getIsCrossSiteCopyable(): bool;

// Indexes, etc.
// -------------------------------------------------------------------------

Expand Down
9 changes: 9 additions & 0 deletions src/base/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,15 @@ public function copyValue(ElementInterface $from, ElementInterface $to): void
$to->setFieldValue($this->handle, $value);
}

/**
* @see CrossSiteCopyableFieldInterface::copyCrossSiteValue()
* @since 5.6.0
*/
public function copyCrossSiteValue(ElementInterface $from, ElementInterface $to): void
{
$this->copyValue($from, $to);
}

/**
* @inheritdoc
*/
Expand Down
72 changes: 72 additions & 0 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use craft\events\DefineElementEditorHtmlEvent;
use craft\events\DraftEvent;
use craft\fieldlayoutelements\BaseField;
use craft\fieldlayoutelements\CustomField;
use craft\fields\Matrix;
use craft\helpers\ArrayHelper;
use craft\helpers\Component;
Expand Down Expand Up @@ -483,6 +484,74 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null):
return $response;
}

/**
* Copies field/attribute values on an element from one site to another.
*
* @return Response
* @since 5.6.0
*/
public function actionCopyValuesFromSite(): Response
{
$this->requireCpRequest();

/** @var Element|Response|null $element */
$element = $this->_element(checkForProvisionalDraft: true);

if ($element instanceof Response) {
return $element;
}

if (!$element || $element->getIsRevision()) {
throw new BadRequestHttpException('No element was identified by the request.');
}

$copyFromSiteId = (int)$this->request->getRequiredBodyParam('fromSiteId');
$this->requirePermission("editSite:$copyFromSiteId");

$layoutElementUid = $this->request->getRequiredBodyParam('layoutElementUid');
$namespace = $this->request->getBodyParam('namespace');

$fromElement = $element::find()
->id($element->id)
->structureId($element->structureId)
->siteId($copyFromSiteId)
->drafts(null)
->provisionalDrafts(null)
->one();

if (!$fromElement) {
throw new UnsupportedSiteException($element, $copyFromSiteId, 'Attempting to copy element content from an unsupported site.');
}

$layoutElement = $element->getFieldLayout()->getElementByUid($layoutElementUid);
if (!$layoutElement instanceof BaseField || !$layoutElement->isCrossSiteCopyable($element)) {
throw new BadRequestHttpException("Invalid layout element UUID: $layoutElementUid");
}
if ($layoutElement instanceof CustomField) {
$layoutElement->getField()->copyCrossSiteValue($fromElement, $element);
} else {
$attribute = $layoutElement->attribute();
$element->$attribute = $fromElement->$attribute;
}

$view = $this->getView();
$html = $view->namespaceInputs(fn() => $layoutElement->formHtml($element), $namespace);

if ($html) {
$html = Html::modifyTagAttributes($html, [
'data' => [
'layout-element' => $layoutElement->uid,
],
]);
}

return $this->_asSuccess(Craft::t('app', 'Field value copied.'), $element, [
'fieldHtml' => $html,
'headHtml' => $view->getHeadHtml(),
'bodyHtml' => $view->getBodyHtml(),
]);
}

/**
* Returns an element revisions index screen.
*
Expand Down Expand Up @@ -2279,6 +2348,9 @@ private function _elementById(
->siteId($siteId)
->preferSites($preferSites)
->unique()
->drafts(null)
->provisionalDrafts(null)
->revisions(null)
->status(null)
->one();

Expand Down
55 changes: 51 additions & 4 deletions src/fieldlayoutelements/BaseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,40 @@ public function formHtml(?ElementInterface $element = null, bool $static = false
$instructions = $this->instructions($element, $static);
$tip = $this->tip($element, $static);
$warning = $this->warning($element, $static);
$translatable = $this->translatable($element, $static);
$actionMenuItems = $this->actionMenuItems($element, $static);

if (
$this->uid &&
$element?->id &&
!$static &&
$this->isCrossSiteCopyable($element) &&
$this->translatable($element, $static) &&
$element->getIsCrossSiteCopyable()
) {
// prepare namespace for the purpose of copying
$namespace = Craft::$app->getView()->getNamespace();

$actionMenuItems = array_filter([
[
'icon' => 'clone',
'label' => Craft::t('app', 'Copy value from site…'),
'attributes' => [
'data' => [
'cross-site-copy' => true,
'element-id' => $element->id,
'layout-element' => $this->uid,
'label' => $label,
'namespace' => ($namespace && $namespace !== 'field')
? StringHelper::removeRight($namespace, '[fields]')
: null,
],
],
],
!empty($actionMenuItems) ? ['type' => 'hr'] : null,
...$actionMenuItems,
]);
}

return Cp::fieldHtml($inputHtml, [
'fieldset' => $this->useFieldset(),
Expand All @@ -395,9 +429,9 @@ public function formHtml(?ElementInterface $element = null, bool $static = false
'tip' => $tip !== null ? Html::encode($tip) : null,
'warning' => $warning !== null ? Html::encode($warning) : null,
'orientation' => $this->orientation($element, $static),
'translatable' => $this->translatable($element, $static),
'translatable' => $translatable,
'translationDescription' => $this->translationDescription($element, $static),
'actionMenuItems' => $this->actionMenuItems(),
'actionMenuItems' => $actionMenuItems,
'errors' => !$static ? $this->errors($element) : [],
]);
}
Expand Down Expand Up @@ -780,15 +814,28 @@ protected function translationDescription(?ElementInterface $element = null, boo
return null;
}

/**
* Returns whether field supports copying its value across sites.
*
* @param ElementInterface $element
* @return bool
*/
public function isCrossSiteCopyable(ElementInterface $element): bool
{
return false;
}

/**
* Returns any action menu items that should be shown for the field.
*
* See [[\craft\helpers\Cp::disclosureMenu()]] for documentation on supported item properties.
* See [[\craft\helpers\Cp::disclosureMenu()]] for documentation on supported item properties.
*
* @param ElementInterface|null $element The element the form is being rendered for
* @param bool $static Whether the form should be static (non-interactive)
* @return array
* @since 5.6.0
*/
protected function actionMenuItems(): array
protected function actionMenuItems(?ElementInterface $element = null, bool $static = false): array
{
return [];
}
Expand Down
11 changes: 10 additions & 1 deletion src/fieldlayoutelements/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Craft;
use craft\base\Actionable;
use craft\base\CrossSiteCopyableFieldInterface;
use craft\base\ElementInterface;
use craft\base\FieldInterface;
use craft\base\PreviewableFieldInterface;
Expand Down Expand Up @@ -428,7 +429,15 @@ protected function translationDescription(?ElementInterface $element = null, boo
/**
* @inheritdoc
*/
protected function actionMenuItems(): array
public function isCrossSiteCopyable(ElementInterface $element): bool
{
return $this->_field instanceof CrossSiteCopyableFieldInterface && $this->_field->getIsTranslatable($element);
}

/**
* @inheritdoc
*/
protected function actionMenuItems(?ElementInterface $element = null, bool $static = false): array
{
if ($this->_field instanceof Actionable) {
$items = $this->_field->getActionMenuItems();
Expand Down
8 changes: 8 additions & 0 deletions src/fieldlayoutelements/TitleField.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@ public function defaultLabel(?ElementInterface $element = null, bool $static = f
{
return Craft::t('app', 'Title');
}

/**
* @inheritdoc
*/
public function isCrossSiteCopyable(ElementInterface $element): bool
{
return true;
}
}
8 changes: 8 additions & 0 deletions src/fieldlayoutelements/assets/AltField.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,12 @@ protected function translationDescription(?ElementInterface $element = null, boo

return ElementHelper::translationDescription($element->getVolume()->altTranslationMethod);
}

/**
* @inheritdoc
*/
public function isCrossSiteCopyable(ElementInterface $element): bool
{
return true;
}
}
Loading
Loading