Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Extend DataObject via subclass (I think this is what I want?)

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

Page: 1
Go to End
Author Topic: 300 Views
  • Peavers
    Avatar
    Community Member
    8 Posts

    Extend DataObject via subclass (I think this is what I want?) Link to this post

    How do I extend/customize a function in a dataobject via subclassing?

    I have created a custom class:

    class CustomEditableFormField extends EditableFormField
    {
    public function getFieldConfiguration()
    {
    //Do custom stuff
    }
    }


    I then added:

    Injector:
    EditableFormField:
    class: CustomEditableFormField

    In my config.yml but the subclass is still being ignored. Do I need to include all the functions of EditableFormField like an interface, or is there something bigger I'm missing?

    Note: Same question on SO https://stackoverflow.com/questions/23352571/silverstripe-extend-dataobject-via-subclass

  • Tim Snadden
    Avatar
    Community Member
    32 Posts
  • Peavers
    Avatar
    Community Member
    8 Posts

    Re: Extend DataObject via subclass (I think this is what I want?) Link to this post

    It was my understanding that in order to use DataExtension, the calling method needs to have a hook. The class I'm trying to extend has no such hooks. I could add one, but then I'm still modifying the core of that module which defeats the entire purpose.

    Attempted anyhow

    class CustomEditableFormField extends DataExtension
    {

    public function getFieldConfiguration()
    {
    [...]

    $customField= new TextField(
    $this->owner->getSettingName('customField'),
    _t('customField', 'Custom field'),
    $this->owner->getSetting('customField')
    );

    $fields = FieldList::create(
    $ec,
    $right,
    $customField
    );

    [...]
    }

    }

    EditableFormField:
    extensions:
    - CustomEditableFormField

    Returns no errors, but doesn't add the customfield as expected.

    Note the code to add the customfield works fine if I add it to the core module.

    So that leaves me to think the injection point isn't correct/added but not sure how to solve that?

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