简体   繁体   English

SilverStripe SiteConfig标题栏操作

[英]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. 我知道在父类SiteConfigTitle字段存储在变量中。 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM