Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Adding default value to some fields in CMS doesn't work


Go to End


1118 Views

Avatar
_Matt

Community Member, 29 Posts

27 November 2014 at 11:06pm

Edited: 27/11/2014 11:14pm

I'm trying to add a default value to an HtmlEditorField in admin. I have it working on TextFields, but for some reason it just won't work on HtmlEditorFields.

Here's a snippet of my code, edited down to just the relevant bits:

<?php

class SiteConfigExtension extends DataExtension
{
    private static $db = array(
        'Message' => 'HTMLText'
    );

    public function updateCMSFields(FieldList $fields)
    {
        $fields->addFieldsToTab('Root.Main', array(
            $a = new TextAreaField('Message', 'Message', '<h2>Default Message...</h2>'),
        ));
        $a->setRows(5);

Any ideas?

By the way, this is a problem that keeps occurring for me in various scenarios (not just with HtmlEditorFields but also with DropdownFields for example), but I've been unable to pin down the cause - it seems quite random.