Hi everyone
I've recently been working on understanding SilverStripe but I've encountered an issue I couldn't solve so far.
It basically involves 3 classes:
- Task
- Member Extension
- MemberTask
The idea is to be able to have an editable list of tasks through TaskAdmin. When creating/editing a task through the TaskAdmin it should not only be possible to change name/description etc, but also to assign/remove them to/from a Member. (which is working)
The problem is that I also want to be able to see (and edit) the assigned Tasks when looking at a Member. This doesn't work and I'm not sure why.
My Task DataObject in its simplest form:
class Task extends DataObject
{
private static $db = array (
'Name' => 'Varchar',
'Description' => 'Text',
);
private static $has_one = array (
'TaskImage' => 'Image'
);
private static $many_many = array (
'Members' => 'Member'
);
}
So far so good.
MyMemberExtension and TaskMember is where I don't seem to get it working:
MyMemberExtension:
<?php
class MyMemberExtension extends DataExtension {
private static $many_many = array (
'Tasks' => 'Task'
);
public function updateCMSFields(FieldList $fields) {
$source = Task::get()->map('ID','Title')->toArray();
$fields->addFieldsToTab('Root.Main', array(
TextField::create('Name'),
TextField::create('Description'),
ListBoxField::create('Tasks', 'Tasks')->setMultiple(true)->setSource($source)
));
}
}
}
MemberTask:
class MemberTask extends DataObject
{
private static $has_one = array (
'Member' => 'Member',
'Task' => 'Task',
);
private static $belongs_many_many = array (
'Members' => 'Member',
'Task' => 'Task',
);
}
Anyone has an idea what I'm doing wrong? My suspicion is that I messed up MemberTask and the updateCMSFields in the Member Extension.