我正在尝试在 BlogPost 摘要视图中添加标题颜色选项。 我将枚举字段添加到数据库中,并且我想在 BlogPost 标题下添加下拉/选择字段。 我不确定要使用哪种字段类型以及如何正确设置它。
class BlogPostExtension extends DataExtension { private static $db = [ 'ArchiveDate' => 'Date', 'TitleColor' => "Enum(array('black','red','green'))" // works only with this syntax ]; private static $defaults = [ 'TitleColor' => 'black' ]; public function updateCMSFields(FieldList $fields) { $fields->push(new DateField('ArchiveDate', 'Archive date')); $fields->push(new DropdownField('TitleColor','Color')); // doesn't populate the dropdown field // $fields->push(new SelectField('TitleColor','Color')); // cannot instantiate abstract class 'SelectField' } }
P粉1139388802023-09-17 11:38:55
如果有人感兴趣 - 我是这样解决的:
public function updateCMSFields(FieldList $fields) { $fields->push(new DateField('ArchiveDate', 'Archive date')); $fields->push(new DropdownField('TitleColor','Color', $this->getEnums())); } private function getEnums() { return singleton('SilverStripe\Blog\Model\BlogPost')->dbObject('TitleColor')->enumValues(); }