所以,首先是免责声明:当谈到SilverStripe时,我有点像菜鸟,但是这个让我感到震惊。
我正在使用GridField添加和编辑DataObject中的条目。这一切都很好,而且效果很好。我唯一想知道的是如何更改EDITABLE字段的顺序 - 这不是条目的初始表显示(由$ config设置),一旦你点击“添加”,它就是实际的输入字段新的“或去编辑记录。
目前,Image uploadForm和签名<select>
框位于Body HTMLText字段下方,该字段非常混乱,无法正常工作。我希望它们位于摘要元素正下方的顶部。
我尝试过使用changeFieldOrder(),但是这对GridField对象类型不起作用,而$ fields对输入元素一无所知(我转储它(看看它)并查看了一下)
MediaReleaseItem.php:
class MediaReleaseItem extends DataObject {
static $db = array (
'Title' => 'Varchar',
'DateUpdated' => 'Date',
'Summary' => 'Varchar',
'Image' => 'Varchar',
'Body' => 'HTMLText',
);
private static $has_one = array(
"Image" => "Image",
"MediaReleaseItem" => "MediaReleases",
"Signature" => "MediaReleaseSignature",
);
}
和MediaReleases.php:
class MediaReleases extends Page {
private static $has_many = array(
"MediaReleaseItems" => "MediaReleaseItem",
"Signature" => "MediaReleaseSignature",
);
function getCMSFields() {
$fields = parent::getCMSFields();
$config = GridFieldConfig_RecordEditor::create();
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
'Title'=> 'Title',
'DateUpdated' => 'Date',
'Summary' => 'Summary',
));
$mediaReleasesField = new GridField(
'MediaReleaseItem', // Field name
'Media Releases', // Field title
$this->MediaReleaseItems(),
$config
);
$fields->addFieldToTab('Root.MediaReleaseItems', $mediaReleasesField);
return $fields;
}
}
(Signature只是另一个DataObject,在不同的选项卡上有不同的GridField,我没有包含它的代码,因为它几乎相同。)
答案 0 :(得分:4)
所以,你的意思是当你编辑MediaReleaseItem
这些字段不是你想要的那样的时候?
简单:只需在类getCMSFields()
上定义方法MediaReleaseItem
。
<?php
class MediaReleaseItem extends DataObject {
private static $db = array (
'Title' => 'Varchar',
'DateUpdated' => 'Date',
'Summary' => 'Varchar',
'Image' => 'Varchar',
'Body' => 'HTMLText',
);
private static $has_one = array(
"Image" => "Image",
"MediaReleaseItem" => "MediaReleases",
"Signature" => "MediaReleaseSignature",
);
public function getCMSFields() {
$arrayOfSignatures = MediaReleaseSignature::get()->map()->toArray();
$fields = FieldList::create(array(
TextField::create('Title', 'Title for this Item'),
DateField::create('DateUpdated', 'Updated')->setConfig('showcalendar', true),
TextField::create('Image', 'Image'),
// not sure if it works to have both a DB field and a has_one with the same name
UploadField::create('ImageID', 'Image'),
DropdownField::create('Signature', 'Signature', $arrayOfSignatures),
// you can add more fields here
));
// but you can also add fields here
$fields->insertBefore(TextField::create('Summay', 'Summary'), 'DateUpdated');
$fields->push(HTMLEditorField::create('Body', 'Body Content'));
return $fields;
}
}