What happened?
Description
We have a plugin that let's users clone nested entries into other sites. For instance, if you have a matrix field that have propagation method "Only save entries to the site they were created in", it let's you duplicate a nested entry to a different site.
The essence of what is does is $targetElement = \Craft::$app->elements->duplicateElement($element, ['siteId' => $newSite->id]);, and then $targetElement is added to the matrix field of the element in the other site as a new block.
Prior to 5.6, this worked perfectly. After 5.6, it throws an UnsupportedSiteException with message "'Attempting to duplicate an element in an unsupported site.".
I've tracked this down to getPrimaryOwner/getOwner in NestedElementTrait. The owner element has the site id of the duplicated element prior to 5.6, which means that the check for $supportedSites in duplicateElement is a-ok, whereas the owners site id after 5.6 is the site id that the element was duplicated from. But, the underlying issue seems to be that $this->siteId refers to the different sites, depending on whether I'm on 5.5 or 5.6.
I'm not able to track down why this happens though, so I'm not quite sure what changed that resulted in this. And, not quite sure if this is an intended or unintended change? But, it would be nice if it was possible somehow to duplicate nested entries to new sites.
Steps to reproduce
- Create a blank install on Craft 5.5.10.
- Set up two sites, site1 and site2.
- Create a matrix field that has propagation method "Only save entries to the site they were created in".
- Create an entry with a nested entry.
- Query for the nested entry in site1.
- Do
$clonedNestedEntry = \Craft::$app->elements->duplicateElement($nestedEntry, ['siteId' => $site2->id]);
- Upgrade to 5.6 and do the same.
Expected behavior
You should get a new duplicated element in site2.
Actual behavior
It throws an UnsupportedSiteException with message "'Attempting to duplicate an element in an unsupported site.".
Craft CMS version
5.6.5.1 and 5.5.10
PHP version
8.3
Operating system and version
No response
Database type and version
Mysql 8.0
Image driver and version
No response
Installed plugins and versions
What happened?
Description
We have a plugin that let's users clone nested entries into other sites. For instance, if you have a matrix field that have propagation method "Only save entries to the site they were created in", it let's you duplicate a nested entry to a different site.
The essence of what is does is
$targetElement = \Craft::$app->elements->duplicateElement($element, ['siteId' => $newSite->id]);, and then$targetElementis added to the matrix field of the element in the other site as a new block.Prior to 5.6, this worked perfectly. After 5.6, it throws an UnsupportedSiteException with message "'Attempting to duplicate an element in an unsupported site.".
I've tracked this down to
getPrimaryOwner/getOwnerinNestedElementTrait. The owner element has the site id of the duplicated element prior to 5.6, which means that the check for$supportedSitesinduplicateElementis a-ok, whereas the owners site id after 5.6 is the site id that the element was duplicated from. But, the underlying issue seems to be that$this->siteIdrefers to the different sites, depending on whether I'm on 5.5 or 5.6.I'm not able to track down why this happens though, so I'm not quite sure what changed that resulted in this. And, not quite sure if this is an intended or unintended change? But, it would be nice if it was possible somehow to duplicate nested entries to new sites.
Steps to reproduce
$clonedNestedEntry = \Craft::$app->elements->duplicateElement($nestedEntry, ['siteId' => $site2->id]);Expected behavior
You should get a new duplicated element in site2.
Actual behavior
It throws an UnsupportedSiteException with message "'Attempting to duplicate an element in an unsupported site.".
Craft CMS version
5.6.5.1 and 5.5.10
PHP version
8.3
Operating system and version
No response
Database type and version
Mysql 8.0
Image driver and version
No response
Installed plugins and versions