Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

Translatable 3.1 duplicate related dataobjects (onTranslatableCreate)

Go to End

2 Posts   693 Views

Nobrainer Web

Community Member, 138 Posts

7 February 2014 at 11:05pm

For my module Content Blocks:
i would like to handle translations in a simple way.

What i would like to do is, when a page is translated
- duplicate all the many_many Blocks of that page
- change the relation for the Block from page in old language to page in new language

I have seen that there is some kind of hook in on the translatable class: "onTranslatableCreate", but how do i use this, to do the above?

I'm guessing i have to add something along the lines of the following to my

	public function onTranslatableCreate() {
		$pageblocks = $this->owner->Blocks();
		foreach($pageblocks as $orgBlock) {
			$block = $orgBlock->duplicate(false);
			$block->ParentID = $duplicateWidgetArea->ID;

But the function onTranslatableCreate does not get called.

Any help greatly appriciated :o)

Nobrainer Web

Community Member, 138 Posts

10 February 2014 at 3:09am

Ok i figured it out, the following does the job.
Shared for future visitors, hope it helps.
Added this to my class ContentBlocksModule extends DataExtension (extending page)

	* Simple support for Translatable, when a page is translated, copy all content blocks and relate to translated page
	public function onTranslatableCreate() {
		$translatedPage = $this->owner;
		// Getting the parent translation
		//$originalPage = $translatedPage->getTranslation('en_US');
		print $this->owner->default_locale();
		$originalPage = $this->owner->getTranslation($this->owner->default_locale());
		foreach($originalPage->Blocks() as $originalBlock) {
			$block = $originalBlock->duplicate(true);