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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Using Injector instead of Object::useCustomClass to replace single method.


Go to End


2 Posts   1435 Views

Avatar
Schippie

Community Member, 38 Posts

26 January 2015 at 10:50pm

Edited: 27/01/2015 12:10am

I want to override the Member->update() functionality and seeing as this is not possible through data Extensions and their are no hooks in the update function i was wondering what the correct way of doing this is?

I tried it through the injector pattern but this did not really help me much seeing as now the Member table is not even created anymore when i use a structure along the form of:

config.yml

Injector:
  Member:
    class: CustomMember

CustomerMember:

class CustomMember extends Member
{
    public function update($data)  {
        return parent::update($data);
    }
}

And while i probably could do this through the Object:useCustomClass() i was wondering if this was possible through the Injector in anyway to only overwrite one single method.

Edit

I just tried it on the Member class but this is pointless in the current situation even with Object:useCustomClass() seeing as DataObject:get() does not look through this list. And simply grabs the class you use instead of any class that might overwrite this.
So i am now really looking for a way to overwrite build in functionality like update or delete for for example Member.

Avatar
BenWu

Community Member, 97 Posts

29 July 2016 at 11:14am

Using Injector to replace a dataobject class is not going to work as it involves creating tables and some tricky SQL query will also fail. I only use Injector to replace a non dataobject class like Email / Controller

You need to write a new method with a different name than 'update' in a DataExtension and call this new method manually rather than using the built-in 'update' method.