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

v6 - Localised copy doesn't trigger when ClassName changes #713

Open
mfendeksilverstripe opened this issue May 27, 2021 · 3 comments
Open

Comments

@mfendeksilverstripe
Copy link
Contributor

Localised copy doesn't trigger when ClassName changes

This may be an edge case but it's quite important for the Fluent + Elemental setup

Test setup

Page - "out of the box" model type
CustomPage - page with a has_one relation which uses localised_copy and this relation is automatically populated when a page is created (like ElementalArea)

  • Create new Page, localise in int and us
  • Current locale is int
  • Change Page class to CustomPage and save
  • This triggers the relation to be populated for the int locale but not for the us locale

The most common case is ElementalArea as this model is automatically attached when ClassName is changed (as the page relation becomes available).

Possible solution

Something like if we have localised_copy setup then we wold search for all localised records of the current model and check if this relation is populated. If it's not populated we would duplicate the related model from the current locale and attach. This should happen onAfterWrite(). We should probably use writeWithoutVersion or raw query if needed to attach relations.

@tractorcow
Copy link
Collaborator

tractorcow commented May 27, 2021

and this relation is automatically populated when a page is created (like ElementalArea)

Should localised_copy create a brand new record each time, or only copy an existing record to the new locale when it's localised? I'm not sure it's clear that's the expectation. Especially if you want localised_copy an an optional record (e.g. page banner, but there doesn't HAVE to be a banner).

@mfendeksilverstripe
Copy link
Contributor Author

mfendeksilverstripe commented Jun 9, 2021

My understanding is that localised_copy means you always create a new record. For example if you copy to the same locale twice the second time will create a new record. I'll review how localised copy works currently in detail and ideally I'll put up a POC for review. Maybe this is something that belongs to the Fluent/Elemental module though.

@mfendeksilverstripe
Copy link
Contributor Author

@tractorcow I've added a POC for this #717

Please have a look and let me know your thoughts ;-)

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

No branches or pull requests

2 participants