Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » List has_many-object's title as column on 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: 520 Views
  • ROlckers
    Avatar
    Community Member
    8 Posts

    List has_many-object's title as column on DOM Link to this post

    Good day,

    I have a data object manager loaded on a page as per below:

    class XYZPage extends Page
    {
       static $has_many = array (
          'CustomModels' => 'CustomModel'
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab("Root.Content.CustomWidgets", new DataObjectManager(
             $this,
             'CustomModels',
             'CustomModel',
             array('CustomName'=>'Custom Model Name', 'CustomParentPageID'=>'Custom Parent Page ID'),
             'getCMSFields_forPopup'
          ));
          return $fields;
       }
    }

    class CustomModel extends DataObject
    {
       static $db = array (
          'CustomName' => 'varchar(255)'
       );
       
       static $has_one = array (
          'CustomParentPage' => 'SiteTree'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('WidgetName', 'Widget Name'),
             new SimpleTreeDropdownField('CustomParentPageID', 'Parent Page', 'SiteTree')
          );
       }
    }

    The CustomModel has a one to one relationship with the SiteTree table (CustomParentPage). In the getCMSFields function (XYZPage) I can print the CustomParentPageID as a column in the DOM. Is it possible to add that page Title (or other properties related to that class) in the DOM? If so would someone mind steering me in the right direction?

    I would ideally like to do something similar to this:

          $fields->addFieldToTab("Root.Content.CustomWidgets", new DataObjectManager(
             $this,
             'CustomModels',
             'CustomModel',
             array('CustomName'=>'Custom Model Name', 'CustomParentPageID'=>'Custom Parent Page ID',
                'CustomParentPage->Title'=>'Custom Parent Page Title' // <-- is something like this possible?
             ),
             'getCMSFields_forPopup'
          ));

  • ROlckers
    Avatar
    Community Member
    8 Posts
    520 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.