translatable-dataobject icon indicating copy to clipboard operation
translatable-dataobject copied to clipboard

Handling relations

Open thomasbnielsen opened this issue 11 years ago • 2 comments

Hi,

First of all, thanks for sharing this module :-)

I'm trying to get my ModelAdmin set up for the client to handle 2 languages. I have a Vessel dataobject that i have extended with Vessel::add_extension('TranslatableDataObject'); I'm able to get my textfields added for translations.

On my dataobject Vessel i have: static $belongs_many_many = array( 'Groups' => 'VesselGroup' );

The question is: How do i handle the relation? I need to add groups to each Vessel, and the groups are a Page in either English for the default language and danish for the secondary.

I can allready manage the groups if i set the language of the ModelAdmin manually by entering ?locale=da_DK in the URL.

Should i choose to use $fields->add($this->getTranslatableTabSet()); and if so, how do i manage the groups?

Or should i do it the same way as pages, where you change the language in the backend? For this option - how do i get some kind of button or dropdown in the ModelAdmin that allows the client to change the locale? (Asking them to type in the URL each time is not an option :-))

Hope you can help

thomasbnielsen avatar Nov 22 '13 08:11 thomasbnielsen

Not sure if I understand your goal correctly. So you already can enter the translations in ModelAdmin, but not the relations? Did you see this: https://github.com/bummzack/translatable-dataobject/issues/12 ?

Wouldn't it be possible to be the other way round, so that you add the Vessels within the Group-Page?

bummzack avatar Nov 22 '13 08:11 bummzack

Thanks for linking issue 12, it's kinda the same. Yes i can turn it around and add the relation in the group page, but that kinda defeats the purpose of the ModelAdmin (i think).

Let me try to explain the problem again: I like the idea of the $fields->add($this->getTranslatableTabSet()); - this allows the client to edit both the Danish and English language in the modeladmin - no need to jump into pages, changing language and so on.

But i have a relation, each of my Vessels belongs to many groups: static $belongs_many_many = array( 'Groups' => 'VesselGroup' ); VesselGroup is a PageType. I would like to be able to set the different groups that a Vessel belongs to in ModelAdmin (again, the client should not need to leave ModelAdmin) but since we are not changing the language, i only get the options for the Group pages of the current language.

I'm getting the groups by doing this: $Groups = DataObject::get('VesselGroup')->sort(array('ParentID' => 'ASC','Title'=>'ASC')); $fields->addFieldToTab("Root.Groups", new CheckboxsetField('Groups', 'Grupper', $Groups->map('ID', 'CheckboxSummary')));

I think the best solution would be to add an option to change the language in the modeladmin - as sugested in #12. and then not use getTranslatableTabSet, but implement the getCMSFields method manually.

Sorry for the bad explanations, but i hope you can follow me.

thomasbnielsen avatar Nov 22 '13 11:11 thomasbnielsen