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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Managing different page's DOM


Reply


440 Views

Avatar
pali

Community Member, 33 Posts

1 January 2012 at 1:23am

Edited: 01/01/2012 1:24am

Hi,

im trying to manage DOM from different site - as an example - i have default page with photos and this page is translated to different language. I would like to show Photos from default lang on translated Page (in backend, frontend is OK).

Im trying this w/o success:

PhotosPage.php

class PhotosPage extends Page {
   
   public static $has_many = array(
'Photos' => 'Photo'
   );
   
   public function getCMSFields() {
$fields = parent::getCMSFields();

      if ($this->Locale != Translatable::default_locale()) {
         $tPage = $this->getTranslation(Translatable::default_locale());
         $filter = 'PhotosPageID = ' . $tPage->ID;
         $manager = new DataObjectManager(
            $tPage,
            'Photos',
            'Photo',
            array(
               'Name' => 'Názov',
            ), // Headings
            'getCMSFields_forPopup',
            $filter
         );
         $manager->setPermissions(
          array(
          "show"
          )
         );
      } else {
         $manager = new ImageDataObjectManager(
            $this,
            'Photos',
            'Photo',
            'PhotoImage',
            array(
               'Name' => 'Názov',
            ), // Headings
            'getCMSFields_forPopup'
         );
         $manager->setUploadFolder('Photos/'.$this->ID);
      }

$fields->addFieldToTab("Root.Content.Photos", $manager);

return $fields;
}

...

Photos.php:

class Photo extends DataObject
{
   static $db = array (
      'Name' => 'Text'
   );
   
   static $has_one = array (
      'PhotoImage' => 'Image',
'PhotosPage' => 'PhotosPage'
   );
   
   public function getCMSFields_forPopup()
   {
      $fields = new FieldSet(
         new TextField('Name')
      );
      $this->extend('updateCMSFields_forPopup', $fields);
      return $fields;
   }
   
   public function onBeforeWrite() {
      if (empty($this->Name)) {
         $this->Name = $this->PhotosPage()->Title;
      }   
      parent::onBeforeWrite();
   }

Regards

Pali