XF 2.0 Class extension problem

_PkZ_

Active member
I am trying to extend \XF\CustomField\DefinitionSet but i cant get it to work. I have registered the extension in admin but it looks like this doesnt work somehow.

I have defined my class like this:
class DefinitionSet extends XFCP_DefinitionSet

Are there any classes that cant be extended this way?
 
Yes, some classes can't be extended.

Any class which is extendable is run through our extendClass function, rather than being instantiated directly.

So if you search for files you'll see that when we load the DefinitionSet object we do it like this:
PHP:
return new DefinitionSet($fieldInfo);
That's instantiated directly so there's nowhere we can hook into it and apply class extensions.

If it were something like this:
PHP:
$class = 'XF\CustomField\DefinitionSet';
$class = \XF::extendClass($class);
return new $class($fieldInfo);
Then it's extendable.

There's usually a reason we've decided not to make a class extendable, so it's generally just a case of finding another approach.
 
Back
Top Bottom