简体   繁体   中英

Unable to add custom site config to Silverstripe 4

Im following the original docs but /dev/build is not generating the db fields and the form fields are not getting generated either.

this is the value of my app/_config/app.yml

---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
  project: app
---
Silverstripe\SiteConfig\SiteConfig:
  extensions:
    - CustomSiteConfig
---
SilverStripe\Admin\LeftAndMain:
  extra_requirements_css:
    - public/resources/admin/css/custom.css

and this is my app/src/extensions/CustomSiteConfig.php

<?php

use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\ORM\DataExtension;

class CustomSiteConfig extends DataExtension
{

    private static $db = [
        'FooterContent' => 'HTMLText'
    ];

    public function updateCMSFields(FieldList $fields)
    {
        $fields->addFieldToTab("Root.Main",
            new HTMLEditorField("FooterContent", "Footer Content")
        );
    }
}

Silverstripe is new to me and maybe I'm missing something here. But I'm looking for an hour now and cant get it to work.

I think the problem is in the way you're structuring your YAML:

---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
  project: app
---
Silverstripe\SiteConfig\SiteConfig:
  extensions:
    - CustomSiteConfig
---
SilverStripe\Admin\LeftAndMain:
  extra_requirements_css:
    - public/resources/admin/css/custom.css

The --- blocks are notating title blocks for each section of config, so the dividers you're using after the section with Name: myproject in it are creating more title blocks which won't be treated as config any more.

Try this:

---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
  project: app

Silverstripe\SiteConfig\SiteConfig:
  extensions:
    - CustomSiteConfig

SilverStripe\Admin\LeftAndMain:
  extra_requirements_css:
    - public/resources/admin/css/custom.css

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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