Closed riasvdv closed 6 years ago
This is strange, because the $entry->getSupportedSites()
should return either an empty array or an array with the structure:
/**
* @inheritdoc
*/
public function getSupportedSites(): array
{
$section = $this->getSection();
$sites = [];
foreach ($section->getSiteSettings() as $siteSettings) {
if ($section->propagateEntries || $siteSettings->siteId == $this->siteId) {
$sites[] = [
'siteId' => $siteSettings->siteId,
'enabledByDefault' => $siteSettings->enabledByDefault
];
}
}
return $sites;
}
So even if the function would be called twice, it should not return the array you are experiencing. This works only for entries of course.
Maybe something else calls the event EVENT_BEFORE_SAVE_ELEMENT
and triggers it and falls flat at the line.
Could you explain a little bit more about the setup? What type of section? Which fields do you use? For now I will add a check, if the element is an entry and if not do not even call the function.
I couldn't reproduce it (I think Matrix is the culprit). But I still added the check, it's cleaner than just hope everything works. :) https://github.com/Goldinteractive/craft3-sitecopy/commit/592d727390ef619f84980bd007e67e7263e08383
This should fix your issue. Just update the plugin.
Works! Seems like Matrix is indeed triggering the event. Thanks for the quick fix
Getting this error when trying to copy to another site. It seems the
syncElementContent
function is being called twice from examining the logs:The first time
$supportedSites
contains this:But the second time it's only this:
Which causes the illegal string offset