[英]SilverStripe SiteConfig titlefield manipulation
I've set up a SiteConfig
extension (declared in yml, tested and confirmed) through which I'm trying to change the Title
field (the one for Site title) to a read only field. 我已经设置了
SiteConfig
扩展名(已在yml中声明,已测试并确认),通过该扩展名我试图将“ Title
字段(“网站标题”的字段)更改为只读字段。
I know that in the parent class SiteConfig
the Title
Field is stored in a variable. 我知道在父类
SiteConfig
, Title
字段存储在变量中。 SiteConfig line 85: $titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title"))
SiteConfig第85行:
$titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title"))
So in my extension SiteConfigTweaks extends DataExtensions
I've tried: 因此,在我的扩展
SiteConfigTweaks extends DataExtensions
我尝试过的SiteConfigTweaks extends DataExtensions
:
public function updateCMSFields(FieldList $fields) {
$titleField->performReadonlyTransformation();
}
But this doesn't do the trick. 但这并不能解决问题。 What am I missing here?
我在这里想念什么?
I suggest you do the following: 我建议您执行以下操作:
public function updateCMSFields(FieldList $fields)
{
if ($titleField = $fields->dataFieldByName('Title')) {
$fields->replaceField(
'Title',
$titleField->performReadonlyTransformation()
);
}
}
First you get the existing Title-field and also check for its existence. 首先,您将获得现有的“标题”字段,并检查其是否存在。 Then you replace the field with its read-only transformed variant.
然后,用其只读的转换变量替换该字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.