Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » [SOLVED] Show SiteTree inside getCMSFields_forPopup()

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: 984 Views
  • Mrfixer
    Avatar
    Community Member
    49 Posts

    [SOLVED] Show SiteTree inside getCMSFields_forPopup() Link to this post

    Hi im trying to get the sitetree to show inside the dataobjectmanager popup, heres what im hoping to achieve

    1) upload a set of images
    2) apply captions and titles to each
    3) add an internal link that echos out on page inside a span. (like a "read more")

    1) and 2) are no problem, working great, applying the sitetree however is giving me grief, this is what i have..

    My Class file:

    <?php
    class HomepageImageResource extends DataObject
    {
    static $db = array (
    'HomepageTitle' => 'Text',
    'HomepageCaption' => 'Text'
    );

    static $has_one = array (
    'HomepageAttachment' => 'Image',
    'HomepageInternalLink' => "SiteTree"
    );

    public function getCMSFields_forPopup()
    {
    return new FieldSet(
    new TextField('HomepageTitle'),
    new TextareaField('HomepageCaption'),
    new FileIFrameField('HomepageAttachment')
    // new SimpleTreeDropdownField( 'HomepageInternalLinkID', 'HomepageInternalLink', 'SiteTree' )
    );
    }
    }

    now onto my HomePage extends Page: (note the "// this causes me the error" comment) without that line all works ok but no sitetree

    class HomePage extends Page {
    static $db = array(
    );
    static $has_one = array(
    );

    static $has_many = array (
    'HomepageImages' => 'HomePageImageResource'
    );

    function getCMSFields() {

    $fields = parent::getCMSFields();

    $fields->removeFieldFromTab('Root.Content.Main', 'Content');

    $fields = parent::getCMSFields();
    $homepagemanager = new ImageDataObjectManager(
    $this, // Controller
    'HomepageImages',
    'HomepageImageResource',
    'HomepageAttachment',
    'HomepageInternalLink', // this causes me the error"

    array(
    'HomepageTitle' => 'HomepageTitle',
    'HomepageCaption' => 'HomepageCaption'
    ), // Headings
    'getCMSFields_forPopup'
    );
    $fields->addFieldToTab("Root.Content.Main",$homepagemanager);

    $fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent');

    return $fields;
    }

    }

    UPDATE: Marked as Solved
    this is what i needed to do to get it working if anyone else comes across this issue:

    In HomePage.php i changed the getCMSFields() function to:

    function getCMSFields() {

    $fields = parent::getCMSFields();

    $fields->removeFieldFromTab('Root.Content.Main', 'Content');

    $fields = parent::getCMSFields();
    $homepagemanager = new ImageDataObjectManager(
    $this, // Controller
    'HomepageImages', // Source name
    'HomepageImageResource', // Source class
    'HomepageAttachment', // File name on DataObject
    //'HomepageInternalLink',

    array(
    'HomepageTitle' => 'HomepageTitle',
    'HomepageCaption' => 'HomepageCaption'
    ),
    'getCMSFields_forPopup'
    );

    $homepagemanager->setRelationAutoSetting(false);

    $fields->addFieldToTab("Root.Content.Main",$homepagemanager);

    $fields->removeFieldFromTab('Root.Content.Main', 'MainPageContent');

    return $fields;
    }

    overriding default setRelationAutoSetting to false

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