Hello
I have a "MonkeeBlogPage" wich has_Many "MonkeeBlogEntries"
"MonkeeBolgEntry" has_one MonkeeBlogPage
Now in SS2.4, using DataObjectManager the Relation would be saved and added automatically.
With GridField in SS3 this is not the case.
Any Solution for that case? If i add a DataObject trought a Gridfield on a Page, it is not very Convenient that i have to choose the belonging Page on every new Dataobject, that should happen automatically. How can i accomplish this?
<?php
class MonkeeBlogPage extends Page {
public static $db = array(
);
public static $has_one = array(
);
public static $has_many = array(
'MonkeeBlogEntries' => 'MonkeeBlogEntry',
'MonkeeBlogCategory' => 'MonkeeBlogCategory'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(10),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm()
);
/* Blog Entries */
$blogGridConfig = $gridFieldConfig;
$blogGridConfig->addComponent(new GridFieldSortableRows('SortOrder'));
$blogGridField = new GridField("MonkeeBlogEntries", "Monkee Blog Entries", DataObject::get('MonkeeBlogEntry'), $blogGridConfig,$this);
$fields->addFieldToTab("Root.Main", $blogGridField,'Content'); // add the grid field to a tab in the CMS
$fields->removeByName('Content');
return $fields;
}
}
and
<?php
class MonkeeBlogEntry extends DataObject {
static $db = array(
'Title' => 'VarChar',
'Content' => 'HTMLText',
'Datum' => 'Date',
'SortOrder' => 'Int'
);
static $has_one = array(
'MonkeeBlogPage' => 'MonkeeBlogPage',
'TitelBild' => 'Image'
);
static $many_many = array(
'MonkeeBlogCategories' => 'MonkeeBlogCategory'
);
static $defaults = array(
'Datum' => 'now'
);
function getCMSFields() {
$datefield = new DateField('Date');
$datefield->setConfig('showcalendar','true');
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(10),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm()
);
return new FieldList(
new TextField('Title'),
new HTMLEditorField('Content'),
$datefield,
new ImageField('TitelBild'),
new GridField("MonkeeBlogCategories", "Kategorien", DataObject::get('MonkeeBlogCategory'), $gridFieldConfig)
);
}
}