Hello,
I'm trying to create a standalone module that will add a new tab to the standard Page type page in the CMS.
This was easy enough to do using a DataExtension but then whenever I tried to add a dataobject to that dataextension via the gridfield I was getting "canView()[..]" errors.
So I back tracked and in my module created a file named Page and added the code I wanted in there and that worked fine with the exception that when I created another module using the same method, the CMS would only show the first module and not the second.
Whats the best approach here? Should I be using a DataExtesion and figuring out what I can't attach objects to it? Or should I be figuring out why having two modules with both the class Page override the last loaded?
edit:
class QuestionAnswer extends DataExtension
{
private static $db = array(
'TestTextField' => 'Varchar(3)',
);
private static $has_many = array(
'FAQ' => 'FAQ'
);
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldsToTab('Root.QuestionsAndAnswers', array(
HeaderField::create("Questions"),
GridField::create('FAQ', 'Questions and Answers', FAQ::get(), GridFieldConfig_RecordEditor::create())
));
}
class FAQ extends DataObject
{
private static $db = array(
'Title' => 'Varchar(155)',
'Answer' => 'HTMLText',
'SortOrder' => 'Int'
);
private static $has_one = array(
'QuestionAnswer' => 'QuestionAnswer'
);
}
This technically works, but obviously returns all the FAQ objects, rather than just the ones you'd expect. Can someone explain how to resolve this? Using..
GridField::create('FAQ', 'Questions and Answers', $this->FAQ(), GridFieldConfig_RecordEditor::create())
Just returns a white screen (even when in dev, with php debugging enabled) so I'm a little lost.
edit again:
I've solved it by making the dataobject FAQ belong to Page and then referencing $this->owner->FAQ() on the gridfield. This feels really dirty and hackery... Is there a better solution?