Hi again, and good day to everybody.
I'm trying to create a "Friends" or "Affiliates" section for a website, which is meant to store a number of entries divided into categories. I'm trying to find a clean and user-friendly way to do this with SS, since the basic model will repeatedly come to use in my next projects.
Coming from this thread
http://silverstripe.org/dataobjectmanager-module-forum/show/276517#post276517,
i decided to try a different approach, because i was not happy with the way the data was being presented in the admin section. So rather than associating all the "Friends" with one Friend Page Type, and using Category Data Objects, i created several Friend Category Pages inside a Friend Holder, each storing their asssociated Friend Entries.
This gives me an uncluttered Admin section and allows for Drag & Drop Reordering of the Friends in each Category.
What i'm trying to achieve now is a way to, when creating or editing a Friend, select the Category Page Relationship for the Dataobject from a Dropdown field, which would allow to reassociate existing friends to a different Category later on.
Everything is working fine, the Dropdown shows a list of all existing Friend Category Pages, but when saving, the Relationship will not be written to the database. Also, when editing an existing Friend, the Dropdown does not show the correct Page when the Popup opens.
Here's my code:
### FreundeKategorie.php
<?php
class FreundeKategorie extends Page {
static $has_many = array (
'Freunde' => 'Freund'
);
public function getCMSFields() {
$f = parent::getCMSFields();
$manager = new DataObjectManager(
$this, // Controller
'Freunde', // Source name
'Freund', // Source class
array('Name' => 'Name','Url' => 'Url'),
'getCMSFields_forPopup'
);
$f->addFieldToTab("Root.Content.Freunde",$manager);
return $f;
}
}
class FreundeKategorie_Controller extends Page_Controller {
}
### Freund.php
<?php
class Freund extends DataObject {
static $db = array (
'Name' => 'Text',
'Url' => 'Text',
);
static $has_one = array (
'Kategorie' => 'FreundeKategorie',
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField( 'Name', 'Name' ) );
$fields->push( new TextField( 'Url', 'Url (http:// am Anfang nicht vergessen!)' ) );
// build dropdown menu for category (related page) selection
$oData = (DataObject::get('FreundeKategorie'));
if ($oData) $CategoriesSource = $oData->toDropDownMap('ID','Title');
$dropdown = new DropdownField('Kategorie', 'Kategorie', $CategoriesSource);
$fields->push ( $dropdown );
return $fields;
}
}
Am i on the wrong track here? I am sorry if this question seems really basic, i'm just starting to get my around the way things work in SS.
Any help would be greatly appreciated!
All the best,
Andi