Dan*_* H. 1 silverstripe silverstripe-4
我试过:removeFieldFromTab removeByName replaceField
但该领域仍然存在.
use SilverStripe\ORM\DataObject;
use //.....
class Product extends DataObject {
private static $db = [
'ProductName'=>'Varchar',
'TagLine'=>'Text',
'GeneralDescription'=>'HTMLText'
];
private static $has_one = [
'SplashImage'=>Image::Class,
'ProductCategory'=>ProductCategory::Class
];
private static $has_many = [
'ProductImage'=>Image::Class,
'Features'=>'Feature'
];
private static $owns = [
'SplashImage',
'ProductImage'
];
private static $summary_fields = array(
'ProductName'=>'Product Name'
);
private static $searchable_fields = [
];
public function getCMSFields(){
$fields = parent::getCMSFields();
$categoryField = DropdownField::create('ProductCategory', 'Choose Product Category', ProductCategory::get()->map('ID', 'ProductCategoryTitle'));
$fields->replaceField('ProductCategory', $categoryField);
return $fields;
}
}
Run Code Online (Sandbox Code Playgroud)
我没有收到任何错误,但是具有id#的默认下拉字段位于顶部.
对于has_one关系,字段名称应该是<RelationName>ID,所以在您的情况下ProductCategoryID.
您必须将附加ID引用到关系名称,以便SilverStripe按名称从CMS选项卡中删除该字段.
$fields->removeByName('ProductCategoryID');
Run Code Online (Sandbox Code Playgroud)
此外,如果为has_one关系创建自定义字段,请确保将其<RelationName>ID用作字段的名称.例如.要创建下拉列表,请使用:
DropdownField::create(
'ProductCategoryID', // Use RelationName + ID
'Choose Product Category',
ProductCategory::get()->map('ID', 'ProductCategoryTitle')
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
161 次 |
| 最近记录: |