Jump to:

10842 Posts in 2513 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » Userforms (ss3.0) > Extending a Field Type

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 355 Views
  • Futureweb
    Avatar
    Community Member
    232 Posts

    Userforms (ss3.0) > Extending a Field Type Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Userforms (ss3.0) > Extending a Field Type Link to this post

    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

  • Futureweb
    Avatar
    Community Member
    232 Posts

    Re: Userforms (ss3.0) > Extending a Field Type Link to this post

    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...

    355 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.