Search code examples
phpsilverstripesilverstripe-4

How to add custom site config to silverstipe?


I am working on building a module with silverstripe and I wanted to store some custom config for my module in the db. I went through the documentation and this is what I am trying:

By looking at silverstripe documentation:

<?php
namespace Poptin\Silverstripe;

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

class PoptinSiteConfig extends DataExtension 
{
    
    private static $db = [
        'FooterContent' => 'HTMLText'
    ];

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

And in the config file:

Silverstripe\SiteConfig\SiteConfig:
    extensions:
        - \Poptin\SilverStripe\PoptinSiteConfig

But I am not sure what this will do when I run /dev/build/?flush. Will it create a new table for my site config, if yes, is it going to have just one field called FooterContent? I am not sure, where can I read more about this in the docs to understand this before I run it, in case it makes changes to my database, would like to be sure.


Solution

  • DataExtensions add columns to the existing table (fyi, subclasses create new tables but this isn't applicable here).

    With Silverstripe you don't have to think too much about the database; it's managed for you via the ORM.

    Suggested reading:

    The last link specifically addresses your use case