Jump to:

23452 Posts in 18901 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Basic DataObject Question

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 316 Views
  • KenSander
    Avatar
    Community Member
    2 Posts

    Basic DataObject Question Link to this post

    I'm a designer, so pretty newb when it comes to development logic, so these will be really simple questions as I try to learn a bit

    I want a dataobject that will be included on every page. It will contain contact info that will be slightly different on certain pages. I want each page to only have 1 dataobject though many might exist.

    Here is my setup:

    class ContactInfo extends DataObject {
    static $db = array(
    'Title' => 'Varchar',
    'Info' => 'HTMLText'

    );

    static $belongs_many_many = array(
    'Pages' => 'Page'
    );

    }

    public static $many_many = array(
          'Info' => 'ContactInfo'
       );

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

    $contactInfo = new GridField(
    'ContactInfo',
    'Contact Information',
    $this->Info(),
    GridFieldConfig_RelationEditor::create()
    );

    $fields->addFieldToTab('Root.ContactInfo', $contactInfo);
    return $fields;
    }

    Is this the proper way to set this up? I'm finding when I delete a dataobject on the page, it removes it completely and not just from this page. I was under the impression the GridFieldConfig_RelationEditor::create() would allow only the deletion from the page.

    How do I limit it so each page only can include 1? The thing is, I'll have say 3 dataobjects that I want to use across all my pages, so some will be on more than 1 page. I don't want it unique to that page.

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Basic DataObject Question Link to this post

    to fix RelationEditor() from deleting the object do this. I believe this is a bug in 3.0.2 and will hopefully be corrected in the next release.

    $gridFieldConfig = GridFieldConfig_RelationEditor::create();
    $gridFieldConfig->removeComponentsByType('GridFieldDeleteAction');
    $gridFieldConfig->addComponent(new GridFieldDeleteAction(true));
    $contactInfo = new GridField(
    'ContactInfo',
    'Contact Information',
    $this->Info(),
    $gridFieldConfig

    I can't help on limiting it to only one though. I'm interested in learning that myself. If i do figure out a solution i'll be sure to post it here.

  • KenSander
    Avatar
    Community Member
    2 Posts

    Re: Basic DataObject Question Link to this post

    Oh okay thanks! I thought maybe my relationship was setup incorrect so I was pretty puzzled for a while. A bug makes sense.

    And that would be great if you find anything about limiting it to 1. It isn't urgent for what I'm setting up now, but I think it would be a good feature to know moving forward.

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