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.