View more context

 

kinglozzer

I have a DataObject ImportSystemType which content authors can configure. Later on, during an import CLI job, it’s cloned across to a different DataObject class SystemType (i.e. if a matching SystemType already exists, use that, otherwise create one based on a matching ImportSystemType). Works fine now, but I’m going to add translations to fields. How do I ensure each translated version is cloned across?

kinglozzer

Do I need to wrap the code that copies it in a foreach ($allLocales… or something?

wmk

afaik yes. Have a look at FluentState and Fluent::withState(). There might already be a Fluent hook for duplicate

Conan

@kinglozzer (https://github.com/tractorcow-farm/silverstripe-fluent/issues/579) Fluent does not currently copy translations for a translated data object, I have actually been thinking about opening a PR for this.

  1. FluentState::singleton()->withState(function (FluentState $tempState) use (
  2. $currentDataObject
  3. ) {
  4. $locales = Locale::getLocales();
  5. foreach ($locales as $locale) {
  6. $tempState->setLocale($locale->Locale);
  7.  
  8. // Fetch the data object with a different locale.
  9. $currentTranslatedDataObject = DataObject::get_by_id($currentDataObject->ID);
  10.  
  11. if ($currentTranslatedDataObject->isInDB()) {
  12. // Copy fields.
  13. // Then ->write()..
  14. }
  15. }
  16. });

You can use something like that to duplicate/copy translated fields.

Show 1 attachment(s)
conny-nyman

Currently if you right click a page in the CMS (tree view) and select Duplicate this page only, fluent does not copy the translations for the duplicated page, when you switch locale on the duplicated page it says the page does not exist in this locale yet, and you get the Copy and save, Copy and publish actions.

Is this a bug or a missing feature?

Hide attachment content
wmk

well, a PR for onBeforeDuplicate() would be great! Maybe switchable with a config variable in case you really don't need it. But when you duplicate a DO I suppose to get all content (and if configured all relations) duplicated. Normal text is also duplicated.

Conan

Yes it is a well needed feature, I might have time to look at it during the weekend. 🙂

blueskies

Has anyone had issues with new SiteConfig records being added? I'm suspecting Fluent is doing something odd.... I have a situation now where I have an Extended SiteConfig (with some translatable text-fields) and there are now suddenly 3 SiteConfig records in the database.... When I go to /settings in the CMS it's displaying the content for SiteConfig record #1 but the the website is using the SiteConfig record #3 (the newest one added)....