View more context

 

rista

updating this part and passing 2nd argument to true when making instance of extension it works fine

rista

ok so nothing is now saved on extension, clear.

rista

saving data on owner within extension also fixed the problem

Nik

Hello folks, I have a class that extends the File class on which I am trying to hook onAfterUpload, but without success. Seems like it is just not being called. I am using a normal UploadField with a has_one relation to my custom File class. Any ideas?

gened

Does it extend File? or is it an Extension of File? It needs to be the latter

Nik

It extends file, but then instead of using the File class I am using the custom one. Should that not work?

theruss

@Nik as @gened suggested, you can still subclass Fileif you really need to, but in order to add custom logic to your own onAfterUpload() implementation, it will need to be on a DataEextension subclass that is applied to File

Nik

Thanks. Wasn't aware there was a difference with custom logic in subclassing vs extending. 👍

theruss

The difference in terms of what you can and can't do, comes down to what the framework is permitting. In this case, you can see that File::onAfterUpload() simply calls $this->extend() which indicates that extensions can and should hook into it

theruss

Having said that, I can't see any reason why if your File subclass contained its own onAfterUpload() that it wouldn't also be called, as long as you called parent::onAfterUpload() in it too.

Nik

Yeah, that was my thought too, even though it calls $this->extend it would also need to call the function on my subclass. Might need to look into it a bit more. I'll check if I can get it to work with extensions first and then work it out from there

👍 (1)
Ben

Can anyone explain the difference between various methods of creating an object? e.g:

  1. new TextField();
  2. TextField::create();
  3. Injector::inst()->create('TextField');
nightjarnz

@Ben Yes, the first is the standard (language level) way of doing this