Hi UncleCheese,
I'm trying to (mis)use ManyManyDataObjectManager to manage a relation on an extension of the Member class. However, I get the error:
[User Warning] Can't figure out the data class of
GET /testss/admin/security/EditForm/field/Members/item/2/edit
Line 28 in G:\localhost\testss\dataobject_manager\code\HasManyDataObjectManager.php
Also the SimpleHTMLEditorField doesn't work in the Members pop-up.
Below a simplified test case of the code. The ManyManyDataObjectManager in Page works find, it's the one on Members that breaks. This error doesn't have a high priority for me as I've found a work around from your thread on http://silverstripe.org/customising-the-cms/show/252445?start=0#post252457, but I thought I would report it to you anyway in case it affects other issues too.
Edit: I've tested this with the latest revision (399).
_config.php
DataObject::add_extension('Member', 'Expert');
mysite\code\Expert.php
<?php
class Expert extends Extension {
static $singular_name = 'Expert';
static $plural_name = 'Experts';
function extraStatics() {
return array(
'db' => array(
'Description' => 'HTMLText',
'TitleName' => 'Text',
),
'many_many' => array(
'Pages' => 'Page',
),
'has_one' => array(
'Thumbnail' => 'Image'
),
);
}
public function getCMSFields() {
$fields = parent::getCMSFields();
$this->extend('updateCMSFields', $fields);
return $fields;
}
public function updateCMSFields(&$fields) {
$fields->addFieldToTab("Root.Main", new TextField('TitleName', 'Academic title'), "FirstName");
$fields->addFieldToTab("Root.Description", new SimpleHTMLEditorField("Description", "Description"));
//This does work and shows the many many relation is working
$fields->addFieldToTab("Root.Pages",new CheckboxSetField('Pages','Pages (check all that apply)', DataObject::get("Page")->toDropdownMap()));
$domPages = new ManyManyDataObjectManager($this, "Pages", "Page", array('Title' => 'Title'), "getCMSFields_forPopup", '', 'Surname ASC');
$fields->addFieldToTab("Root.Pages", $domPages);
$fields->addFieldToTab("Root.Thumbnail", new ImageField('Thumbnail', 'Thumbnail'));
return $fields;
}
function getCMSFields_forPopup() {
$fields = new FieldSet(
new TextField("Surname", "Surname")
);
return $fields;
}
}
mysite/code/Page.php
<?php
class Page extends SiteTree {
static $belongs_many_many = array(
'Members' => 'Member',
);
function getCMSFields() {
$fields = parent::getCMSFields();
// It works fine from here
$manager = new ManyManyDataObjectManager($this, "Members", "Member", array('Surname' => 'Surname'), "getCMSFields_forPopup", "", "Surname ASC");
$manager->setPermissions(array());
$fields->addFieldToTab("Root.Content.Experts", $manager);
return $fields;
}
function getCMSFields_forPopup() {
$fields = new FieldSet(
new TextField("Title", "Title")
);
return $fields;
}
}
class Page_Controller extends ContentController {
/**
* An array of actions that can be accessed via a request. Each array element should be an action name, and the
* permissions or conditions required to allow the user to access it.
*
* <code>
* array (
* 'action', // anyone can access this action
* 'action' => true, // same as above
* 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
* 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
* );
* </code>
*
* @var array
*/
public static $allowed_actions = array (
);
public function init() {
parent::init();
// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS('layout');
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
}
}