Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Using DOM on multiple pages

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1705 Views
  • sca123
    Avatar
    Community Member
    61 Posts

    Using DOM on multiple pages Link to this post

    I have integrated DOM as a template and it is working - however, if I use the same template on another page and go to upload records via the DOM CMS, all of records ever added show except for just the records associated to that page.

    How do I setup unique DOM instances on a per page basis (rather than a template basis)

    Thanks in advance.

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Using DOM on multiple pages Link to this post

    Do you have a $has_one relation for the dataobject with its parent page like?

    class MyDataObject extends DataObject{
    static $has_one = array (
          'ParentPageClass' => 'ParentPageClass'

       );

  • sca123
    Avatar
    Community Member
    61 Posts

    Re: Using DOM on multiple pages Link to this post

    Thanks for your advice - I did what I thought to try but just got a redeclare error. My code is as follows, any further assistance would be appreciated.

    HomePage.php (uses DOM)

    class HomePage extends Page
    {
    static $has_many = array (
          'InfoBoxes' => 'InfoBox'
       );

    static $has_one = array(
    );

       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new DataObjectManager(
             $this, // Controller
             'InfoBoxes', // Source name
             'InfoBox', // Source class
             array('Title' => 'Title', 'Description' => 'Description', 'Link' => 'Link', 'Image' => 'Image'), // Headings
             'getCMSFields_forPopup' // Detail fields function or FieldSet

          );

          $f->addFieldToTab("Root.Content.InfoBoxes", $manager);

          return $f;

       }

    MultiBox Template (needs to also have unique DOM instances for each page use)

    static $has_many = array (
          'InfoBoxes' => 'InfoBox'
       );

       function getCMSFields(){
          $fields = parent::getCMSFields();

          $manager = new DataObjectManager(
             $this, // Controller
             'InfoBoxes', // Source name
             'InfoBox', // Source class
             array('Title' => 'Title', 'Description' => 'Description', 'Image' => 'Image'), // Headings
             'getCMSFields_forPopup' // Detail fields function or FieldSet
          );

          $fields->addFieldToTab("Root.Content.InfoBoxes", $manager);
          $fields->addFieldToTab("Root.Content.Main", new ImageField('TopImage'));
          $fields->addFieldToTab("Root.Content.Banners", new HTMLEditorField('BannerArea'));

          return $fields;

       }

    Class InfoBox

    class InfoBox extends DataObject
    {
       static $db = array (
          'Title' => 'Text',
          'Description' => 'Text',
          'Link' => 'Text'
       );

       static $has_one = array (
          'HomePage' => 'HomePage',
          'Image' => 'Image'
       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Title'),
             new TextField('Description'),
             new TextField('Link'),
             new ImageField('Image')
          );
       }
    }

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Using DOM on multiple pages Link to this post

    This seems Double:

    MultiBox Template (needs to also have unique DOM instances for each page use)

    static $has_many = array (
    'InfoBoxes' => 'InfoBox'
    );

    function getCMSFields(){
    $fields = parent::getCMSFields();

    $manager = new DataObjectManager(
    $this, // Controller
    'InfoBoxes', // Source name
    'InfoBox', // Source class
    array('Title' => 'Title', 'Description' => 'Description', 'Image' => 'Image'), // Headings
    'getCMSFields_forPopup' // Detail fields function or FieldSet
    );

    $fields->addFieldToTab("Root.Content.InfoBoxes", $manager);
    $fields->addFieldToTab("Root.Content.Main", new ImageField('TopImage'));
    $fields->addFieldToTab("Root.Content.Banners", new HTMLEditorField('BannerArea'));

    return $fields;

    }

  • sca123
    Avatar
    Community Member
    61 Posts

    Re: Using DOM on multiple pages Link to this post

    Hi there, sorry to be stupid but I'm not sure what you are saying??!?!

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Using DOM on multiple pages Link to this post

    Nothing special

    Just that you have the part that I copied twice in your code...

  • UncleCheese
    Avatar
    4085 Posts

    Re: Using DOM on multiple pages Link to this post

    Yeah what is this?

    MultiBox Template (needs to also have unique DOM instances for each page use)

    static $has_many = array (
    'InfoBoxes' => 'InfoBox'
    );

  • sca123
    Avatar
    Community Member
    61 Posts

    Re: Using DOM on multiple pages Link to this post

    Sorry but as a Newbie I am confused what is being asked. I'm not sure if it will help but refering to the code above, these are what I currently have:

    > HomePage.php - class related to the HomePage template which uses the DOM module (successfully)
    > InfoBox.php - class defining the fields required for each InfoBox of which there are multiple (InfoBoxes) - UncleCheese, I think this is the answer to your question?

    What I need to do is also use the DOM module for template MultiBox, which has class MultiBox.php. However, each page using this template needs to have unique DOM module based data.

    The code attached above shows the code I am trying to use for MultiBox, however at present this is bringing in the DOM data entered via the CMS for HomePage.

    Any further help would be appreciated.

    1705 Views
Page: 1 2
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.