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 from/Copy to overwrites $has_one fields #848

Open
2 tasks done
polhec opened this issue May 14, 2024 · 6 comments
Open
2 tasks done

Copy from/Copy to overwrites $has_one fields #848

polhec opened this issue May 14, 2024 · 6 comments
Labels

Comments

@polhec
Copy link

polhec commented May 14, 2024

Module version(s) affected

5 and up

Description

Copy to and Copy from CMS actions load object in From locale and then write object in To locale. This will overwrite all translated fields on object including all translated $has_one fields.

This behaviour may be unwanted in specific cases like when using Fluent together with Elemental module in indirect translation configuration. In this case $has_one relation is translated and localised page should have different ElementalArea-s.

If page does not exist in target locale, everything is OK as different elemental area is created on write.

Problem emerges when page exists in target locale. In this case ElementalAreaID value is overwritten by value from source locale. Final efect is, that two page localizations share same ElementalArea and all elements. That should not happen when using Elemental in indirect localization configuration.

How to reproduce

Install Elemental extension and fluent.
Configure Elemental extension in indirect translation mode.
Publish page in two different locales.
Add some Elements in each locale.
USe Copy from or Copy To CMS action.

Possible Solution

Different solutions may be possible:

  • do not overwrite translated has_one fields on Copy to/Copy from
  • do not allow copy actions in existing locale
  • when performing copy to delete target locale and recreate it
    ...

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)
@tractorcow
Copy link
Collaborator

I remember this problem coming up several times in the past. One will need to go over the history and investigate the solution that was used in the past. :) I believe there was a module for elemental + fluent that formalised the solution. It was years ago since I last investigated it though, and years still since I've touched elemental. I'm mostly familiar with the problem though.

@tractorcow
Copy link
Collaborator

#499

@polhec
Copy link
Author

polhec commented May 15, 2024

#499 is not really connected to our problem, as both translations already have existing ElementalArea objects.

#625 hints that extension hooks were added to allow extra control for cases like ElementalArea relation.

I think that Copy action should not overwrite has_one relation fields by default as it can not know what kind of data object is linked by it. It is true, that in most cases that is not big problem, as editor can just change related object in CMS afer Copy action has been performed, but in cases like Elemental, that is not possible.

@AljosaB
Copy link
Contributor

AljosaB commented May 22, 2024

To simplify the explained issue, I believe the copy from / copy to should be disabled / grayed out for the locales where translation already exists, which is currently not the case. It should be required to archive the translation, before you're allowed to create a new one.

It also rises the question, what is the procedure when creating translation over existing one - does it just overwrite the fields or is the page being archived first and new instance created (duplicated)? I did some testing tho, if I archive already existing translation and create a new one, the elemental area still gets the same ID as source locale. So the real question is, why does it work ok only the first time?

Either way, this needs some kind of fix, since it's quite destructive... the editor is unable to fix the situation without deleting all translations and start from the scratch.

@tractorcow
Copy link
Collaborator

tractorcow commented May 22, 2024

so essentially, what you want is a set of translate fields that are overwritable (e.g. text fields), but you also want the ability to specify certain fields (e.g. has one relations) are ignored for the purpose of certain actions (e.g. copy from locale), right?

I.e. that some fields can be localised, but have a default action of only copying from another locale if they were blank.

At the moment we make no such distinction, and you would need to write custom code in order to specially exclude those fields I think. However, it's possible we could add a hook (with example overrides) that let you control this action.

Just making sure I understand the problem correctly, as I don't think I understood it properly when I first read your report. :)

@tractorcow
Copy link
Collaborator

I don't think there's an easy or simple solution to this, to be honest. I'll need to think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants