Silverstripe Version: 4.4.x-dev
Question: Getting Uncaught BadMethodCallException: Object->__call(): the method ‘dataFieldByName’ does not exist on ‘SilverStripe\Forms\HTMLEditor\HTMLEditorField’. How can I fix this?
I am attempting to create a simple gridfield
, the only content being HTMLEditorFields
. I am using the GridFieldConfig_RecordEditor
. When I click “Add section” I get an Internal Server Error
. Then, if I refresh the page I get the following error:
Uncaught BadMethodCallException: Object->__call(): the method 'dataFieldByName' does not exist on 'SilverStripe\Forms\HTMLEditor\HTMLEditorField'
.
I have no clue how to solve this. Does anybody have any ideas?
Here is my Page.php
code:
<?php
namespace {
use SilverStripe\CMS\Model\SiteTree;
use Silverstripe\Forms\CheckboxField;
use Silverstripe\Forms\FieldGroup;
use Silverstripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\ORM\DataObject;
class Section extends DataObject {
private static $db = [
'SectionContent' => 'HTMLText'
];
private static $has_one = [
'Page' => Page::class
];
public function getCMSFields() {
return HTMLEditorField::create('SectionContent');
}
}
class Page extends SiteTree {
private static $db = [
'NoParagraphSpace' => 'Boolean',
'TableHorzLine' => 'Boolean',
'TableVertLine' => 'Boolean',
'EmbedPDF' => 'Boolean',
'IncludeSidebar' => 'Boolean',
'IncludeDate' => 'Boolean',
'Date' => 'Date',
'IncludeSections' => 'Boolean'
];
private static $has_many = [
'Sections' => Section::class
];
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab(
'Root.Main',
FieldGroup::create(
CheckboxField::create("NoParagraphSpace", "No Space between paragraphs"),
CheckboxField::create("TableHorzLine", "Horizontal lines between table rows"),
CheckboxField::create("TableVertLine", "Vertical lines between table columns"),
CheckboxField::create("EmbedPDF", "Embed PDFs directly into the page"),
CheckboxField::create("IncludeSidebar", "Include a sidebar in this page"),
CheckboxField::create("IncludeDate", "Include the date the page was last updated at the bottom of the page"),
CheckboxField::create("IncludeSections", "Seperate the page into sections, each in their own box.")
)->setTitle('Options'),
'Content'
);
if ($this->IncludeDate) {
$fields->addFieldToTab('Root.Main', DateField::create('Date', 'Enter the date the page was most recently updated'), 'Metadata');
}
if ($this->IncludeSections) {
$fields->addFieldToTab('Root.Main',
$grid = GridField::create(
'Sections',
'Sections in this page. Seperated by boxes.',
$this->Sections(),
GridFieldConfig_RecordEditor::create()
)
);
}
return $fields;
}
}
}