Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » CTF Source filter

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

Page: 1
Go to End
Author Topic: 1231 Views
  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    CTF Source filter Link to this post

    Hi everyone,
    I know i can show dataobjects in a CTF that are assigned to one page by using the source filter, however i want the dataobject usable by a few different class files, and I'm not sure how to set up the dataobject's has_one relationship. here's what I have:

    (code is in ProductCategory.php, ProductPage.php, and a few others that all extend Page)
    $downloadfield = new ComplexTableField(
       $this,
       'RelatedDownloads',
       'DownloadLink',
       array(
          'LinkName' => 'Name'
       ),
       'getCMSFields',
       "DownloadLink.DownloadlinkToPageID = {$this->ID}"
    );
    $downloadfield->setParentClass('ProductCategory');
    $downloadfield->relationAutoSetting = true;

    class DownloadLink extends DataObject {
       static $db = array(
          'LinkName' => 'Text'
       );
       static $has_one = array(
          'Document' => 'File',
          'DownloadLinkToPage' => 'Page' // (THIS WORKS AS 'ProductCategory' or 'ProductPage')
       );
       function getCMSFields() {
          $fields = new FieldSet();
          $fields -> push(new TextField("LinkName", "Name"));
          $fields -> push(new ImageField('Document'));
          return $fields;
       }
    }

    I'm not sure how to set up the has_one relationship on the DownloadLink class.. I was hoping that the superclass of the ProductCategory and ProductPage classes (Page) would return records to the calling classes but nothing shows up in the CTF. data is created in the database, and the DownloadLink Dataobjects do have the correct 'DownloadLinkToPageID', and everything works if i change Page to ProductPage in the has_one relationship.

    any thoughts?
    thanks,
    -Chris

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: CTF Source filter Link to this post

    I figured it out. Because DownloadLink was being used by multiple classes, and each calling class had the same tables, i made a superclass with the tables, and subclassed from there.

    1231 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.