I have tried: removeFieldFromTab removeByName replaceField
But the field persists.
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;
}
}
I am not getting any errors but the default drop down field that has the id #'s is at the top.
With
has_one
relations the field name should be<RelationName>ID
, so in your caseProductCategoryID
.You have to reference the append ID to the relation name in order for SilverStripe to remove the field from the CMS tab by name.
Also, if you create a custom field for a
has_one
relation, make sure you use<RelationName>ID
as the name for the field. Eg. to create a Dropdown, use: