Faloude Faloude - 1 year ago 120
PHP Question

SilverStripe change field label from parent class


there is a
Site title. I'm trying to change the label of this textfield
through a SiteConfig extension in class
SiteConfigExtension extends DataExtension

Here is the code from siteconfig/code/model/ where it's created:

$fields = new FieldList(
new TabSet("Root",
$tabMain = new Tab('Main',
$titleField = new TextField("Title", _t('SiteConfig.SITETITLE', "Site title")),

Q: What's the easiest way to replace the SiteTitle label without having to remove the field in the SiteConfig extension and re-add it again with the desired label?

Answer Source

Updating the title from SiteConfigExtension uses updateCMSFields...

class SiteConfigExtension extends DataExtension {

    public function updateCMSFields(FieldList $fields) {
        if ($titleField = $fields->dataFieldByName('Title'))
            $titleField->setTitle('my title');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download