I have a scenario where I am trying to assign (has_many) subscriptions to a member. Via the CMS, I would like to be able to edit a member in the security tab, and in the popup window have a dataobjectmanager on the "Subscription" tab, which allows me to add subscriptions to the member.
Catch is, I have a DataObjectDecorator for the Member class. Using the code below, I have it setup so the Dataobjectmanager does appear on the subscription tab, but:
A) it is poorly formatted and
B) after I add the first dataobject, the edit member popup errors from there on in:
[User Error] Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'Member'
Can anyone help me setup this dataobjectmanager on the edit member popup?
MemberDecorator.php:
class MemberDecorator extends DataObjectDecorator {
function extraStatics() {
return array (
'db' => array(
'PhoneNumber' => 'Varchar(255)',
'Status' => "Enum('Active,Disabled','Disabled')",
),
'defaults' => array(
'Status' => 'Disabled'
),
'has_many' => array( 'Subscription' => 'Subscription' ));
}
public function updateCMSFields(FieldSet $fields) {
$fields->addFieldToTab('Root.Subscription',
new DataObjectManager($this->owner, 'Subscription', 'Subscription')
);
}
}
Subscription.php:
<?php
class Subscription extends DataObject {
static $db = array(
'From' => 'Date',
'To' => 'Date',
'Type' => "Enum('Associates, Full')",
'Amount' => 'Varchar(150)',
'Status' => "Enum('Unpaid, Paid', 'Unpaid')"
);
//Fields to show in the DOM table
static $summary_fields = array(
'Member',
'Type',
'Status'
);
static $has_one = array('Member' => 'Member');
static $defaults = array ();
//static $default_sort = "DosageDate DESC";
public function getCMSFields()
{
$fields = parent::getCMSFields();
return $fields;
}
}