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

Support "translating" relationships #499

Open
ScopeyNZ opened this issue Dec 13, 2018 · 2 comments
Open

Support "translating" relationships #499

ScopeyNZ opened this issue Dec 13, 2018 · 2 comments

Comments

@ScopeyNZ
Copy link
Collaborator

ScopeyNZ commented Dec 13, 2018

Description

Currently field_include is pretty adaptable and supports most use cases out of the box including versioning relationships (translate RelationshipID) - but only in some cases.

Take the example of dnadesign/silverstripe-elemental :

It would be a reasonable use case to translate the whole "ElementalArea" (that's the name of the relationship) on a page - different locales/regions require different content, not necessarily different languages. Currently we could try to enable this with:

private static $field_include = [
    'ElementalAreaID',
];

Unfortunately this doesn't really work as there's nothing that will create a new elemental area when being drafted into a new locale so you also have to add something like this:

public function onBeforeWrite() 
{
    parent::onBeforeWrite();

    // if localised page instance is being created proceed to duplicate elemental data
    // NOTE clone elemental only if this page already exists otherwise there is nothing to clone
    if (!$this->isDraftedInLocale() && $this->isInDB()) {
        $elementalArea = $this->ElementalArea();
        $elementalAreaNew = $elementalArea->duplicate();
        $this->ElementalAreaID = $elementalAreaNew->ID;
    }

    return;
}

It would be great if Fluent supported this out of the box where we could instead have something like:

private static $relationship_include = [
    'ElementalArea',
];
@tractorcow
Copy link
Collaborator

What is forceElementalAreaId?

I think the feature needs to be clear that you are forcing a localised relationship to be exclusive to each locale; I.e. exclusively localised relations.

We would need to come up with rules on when / how these are duplicated; Does an initial write force a duplicate to be generated for each locale?

@ScopeyNZ
Copy link
Collaborator Author

What is forceElementalAreaId?

Good question, that is some project code that's not relevant. I'll update the example to exclude that bit

I think the feature needs to be clear that you are forcing a localised relationship to be exclusive to each locale; I.e. exclusively localised relations.

We would need to come up with rules on when / how these are duplicated; Does an initial write force a duplicate to be generated for each locale?

Yeah this is important. You have to be very careful (imo) about whether having an entirely different record for each locale is actually what you want. Elemental areas have a use case - but only because you might want the content to be laid out differently on your page depending on the locale. If you're looking for a shortcut to mark every field in every element as translatable then this is probably not the right solution.

Perhaps this is something that @silverstripeux has an opinion on.

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