Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Managing different page's DOM

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 325 Views
  • pali
    Avatar
    Community Member
    33 Posts

    Managing different page's DOM Link to this post

    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

    325 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.