During the sample content migration I save programmatically the matrix/neo field value in entry using saveElement
method. In field settings is set "Only save blocks to the site they were created in". In the setting of each field block is set under "Entry condition" - site > is one of > correct locale.
So I expect that the field block value is saved only for locale that is set in the settings of the block. It shows/hides the blocks correctly in Control Panel for each locale, but it saves the field block values for all locales, when I save the field value programmatically. Then, in twig templates I have loops for matrix/neo blocks, where I dynamically render all the available blocks on the current page, based on the handle of the block. Here I expect that some blocks are not available on some locales, but they are there.
I've also tried to save an entry separately for each locale:
$entry = new Entry();
$entry->setFieldValues($sampleData);
Craft::$app->getElements()->saveElement($entry);
$entry = Entry::find()->section('...')->slug('...')->one(); // here previous entry is found
$entry->siteId = 2;
$entry->setFieldValues($anotherSampleData);
Craft::$app->getElements()->saveElement($entry, true, false);
But it throughs an error duplicate key value violates unique constraint
.
So maybe I'm doing something wrong? How would you separate different fields/neo field blocks for different locales, and how would you automatically fill the sample content for different locales? Thank you.