Hello hello,
I'm right now extending the ModelAdmin based upon how it is written in the SilverStripe book. Now I included a ManyManyComplexTableField as well and so far everything works just fine.
But I still have a few questions to my code. You can find my 3 Files here:
NewsletterAdmin.php http://pastebin.com/tkgWQdgE
<?php
class NewsletterAdmin extends ModelAdmin {
static $managed_models = array(
'NewsletterContact',
'NewsletterGroup',
);
static $url_segment = 'newsletter';
}
?>
NewsletterContact.php http://pastebin.com/0FzfQqJm
<?php
class NewsletterContact extends Member {
static $singular_name = 'Kontakt';
static $plural_name = 'Kontakte';
static $db = array(
'Gender' => 'Enum("männlich, weiblich")',
'NameTitle' => 'Varchar(100)'
);
static $many_many = array(
'NewsletterGroups' => 'NewsletterGroup',
);
static $field_labels = array(
'Gender' => 'Geschlecht',
'NameTitle' => 'Anrede',
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('Permissions');
$fields->removeByName('Groups');
$fields->removeByName('Password');
$fields->removeByName('Locale');
$fields->removeByName('DateFormat');
$fields->removeByName('TimeFormat');
$fields->removeByName('MemberUserDetailsHeader');
$newsletterGroupTablefield = new ManyManyComplexTableField(
$this,
'NewsletterGroups',
'NewsletterGroup',
array(
'Title' => 'Title'
),
'getCMSFields'
);
$fields->addFieldToTab( 'Root.NewsletterGroups', $newsletterGroupTablefield );
return $fields;
}
}
?>
NewsletterGroup.php http://pastebin.com/N3kBhkZt
<?php
class NewsletterGroup extends DataObject {
static $singular_name = 'NewsletterGruppe';
static $plural_name = 'NewsletterGruppen';
static $db = array(
'Title' => 'Varchar(255)',
);
static $belongs_many_many = array(
'NewsletterContacts' => 'NewsletterContact',
);
static $field_labels = array(
'Title' => 'Titel',
);
function getCMSFields() {
$fields = new FieldSet();
$fields->push( new TextField( 'Title' ) );
return $fields;
}
}
?>
My Questions:
If I create a new NewsletterContact it first only says "Add" in the lower right corner and only if I hit "Add" I get the 3 new buttons "Back", "Delete" and "Save". This wouldn't really matter to me, but on hitting "Add" it only saves me the Name and the Title of the NewsletterContacts but not the NewsletterGroup in the ManyManyComplexTableField. Is this normal behaviour or is there a way, that I can already save all the data on the first click?
And my second question: On first glance, am I making any serious mistakes, which one should never ever make?
Thanks in advance
Cheers,
David