[Vtigercrm-developers] Extend getInstanceById()?

Sukhdev Mohan s.mohan at myti.it
Thu Dec 10 14:23:38 GMT 2020


What happens if you extend the Vtiger_Record_model and then override it? For the record I myself wondering if it’s worth implementing the OOP, sure a “lavoraccio” which loosely translates to harsh work/bad work from Italian considering the amount of things to rewrite :dead:

Best Regards,
Sukhdev Mohan | Software Developer






> Il giorno 10 dic 2020, alle ore 13:28, Alan Lord <alanslists at gmail.com> ha scritto:
> 
> 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
> 
> _______________________________________________
> http://www.vtiger.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20201210/237e4aad/attachment.html>


More information about the vtigercrm-developers mailing list