[Vtigercrm-developers] Extend getInstanceById()?
Alan Lord
alanslists at gmail.com
Thu Dec 10 12:28:01 GMT 2020
In a custom module I would like to extend the Record Model's
getInstanceById() method.
I have a routine I would like run which is a bit like a constructor, but
because of the way the getInstanceById works, I can't use a constructor
because the object is instantiated without a recordId - which I need.
This happens after the object has been instantiated...
> public static function getInstanceById($recordId, $module=null) {
...
> $instance = new $modelClassName();
> return $instance->setData($focus->column_fields)->set('id',$recordId)->setModuleFromInstance($module)->setEntity($focus);
So in my custom Record Model have tried doing something like...
> public static function getInstanceById($recordId, $module=null) {
> $instance = parent::getInstanceById($recordId, $module=null);
> $instance->validateConfig();
> return $instance;
> }
But of course, because the "normal" way to call this method, wherever
you are in Vtiger, is to call
"Vtiger_Record_Model::getInstanceById(...)" then my extended method is
never actually called.
So to make use of my extended method, I have to use
"MyCustom_Record_Model::getInstanceById(...)" explicitly to achieve the
required result.
Is this design choice deliberate? Is there another way?
Cheers
Al
More information about the vtigercrm-developers
mailing list