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.

All other Modules /

Discuss all other Modules here.

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

Userforms (ss3.0) > Extending a Field Type


Go to End


3 Posts   1385 Views

Avatar
JonShutt

Community Member, 244 Posts

12 June 2013 at 10:24am

Hi there,

I'm trying to extend some of the field types in the UserForms module, to add some extra functions, and override some functions.

Eg - EditableLiteralFieldDecorator.php:

<?php

class EditableLiteralFieldDecorator extends DataExtension {

    static $db = array (
        "ExtraField" => "Varchar",
    );

// override to use html editor
    public function getFieldConfiguration() {
        return new FieldList(
            new HtmlEditorField("Fields[$this->ID][CustomSettings][Content]", "HTML", 4, 20, $this->getSetting('Content'))
        );
    }
}

and in the site _config.php file:

Object::add_extension('EditableLiteralField', 'EditableLiteralFieldDecorator');

Dev/build is creating the extra DB fields no problem, but my 'getFieldConfiguration' function isn't being called, the site is just using the 'getFieldConfiguration' function from the core file. Eg, I want my 'getFieldConfiguration' function override the core module 'getFieldConfiguration' function.

Avatar
Willr

Forum Moderator, 5523 Posts

15 June 2013 at 8:19pm

EditableFormField::getFieldConfiguration() doesn't have any extension hooks so you cannot decorate the fields. What you'd need to do is submit a patch to GitHub adding the extension hooks you need.

// EditableFormField::getFieldConfiguration()
$options = new FieldList(
$ec,
$right
);

$this->extend('updateFieldConfiguration', $options);

return $options;

Then you can include a updateFieldConfiguration function in your DataExtension

Avatar
JonShutt

Community Member, 244 Posts

17 June 2013 at 11:17am

Thanks Will,

I've added " $this->extend()" to into the "getFieldConfiguration" function on the "EditableLiteralField" class. Works great.

Seems that different form fields work a bit diferently, when getting the custom fields, and i couldn't see a universal way of adding in the hook for the base EditableFormField class...