[Vtigercrm-developers] Extend getInstanceById()?

Rubén A. Estrada Orozco rulotec1 at gmail.com
Fri Dec 11 18:17:30 GMT 2020


Hi Alan,

I'm not sure I understand your question correctly, but maybe you could try
something like the following hack:

As you know, this is the Vtiger_Record_Model::getInstanceById() function:

[image: image.png]

on lines 303 and 304 you create a an instance based on a class of your
module.
Then on 305 you set the fields, the id, module, and focus.

Why not, in your module's class (MyCustom_Record_Model I think) , override
the "setEntity" function and then do the "validateConfig()" thing inside of
it. Something like:

public class setEntity($focus)
{
    parent::setEntity($focus);
    $this->validateConfig();
}

Does that make sense?

Saludos

Rubén


On Fri, Dec 11, 2020 at 11:50 AM Uma S <uma.s at vtiger.com> wrote:

> Hi Alan,
>
> 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?
>
> Yes! The design choice is deliberate, Core record api getInstanceById()
> should generate the requested module object and instantiate to current
> record.
>
> In the current approach, the only way to invoke the custom
> defined getInstanceById() is as you specified above.
>
> But i do agree with your thought for callback in this case, where the
> constructor trigger is not of much use.
>
> Please do file an issue on code.vtiger.com. So that we can review to take
> it forward.
>
> On Thu, Dec 10, 2020 at 10:36 PM Sukhdev Mohan <s.mohan at myti.it> wrote:
>
>> Ah Sorry I didn’t understood the problem at first. This is indeed an
>> issue worth finding a clever solution.
>>
>>
>> Best Regards,
>> *Sukhdev Mohan* | *Software Developer*
>>
>>
>>
>>
>>
>>
>> Il giorno 10 dic 2020, alle ore 15:39, Alan Lord <alanslists at gmail.com>
>> ha scritto:
>>
>> On 10/12/2020 14:23, Sukhdev Mohan wrote:
>>
>> What happens if you extend the Vtiger_Record_model and then override it?
>>
>>
>> As I said, it makes no difference because the normal way to call it is by
>> using calling Vtiger_Record_Model::getInstanceById() first.
>>
>> It is _this_ function which finds your "MyCustomModule_Record_Model"
>> class and instantiates it. (But this is the child, not the parent).
>>
>> Also in certain places in vtiger, where you might want to access an
>> existing Record Model, say in the DetailView module, you call
>> $this->getRecord(). This Record Model was instantiated by the
>> Vtiger_Record_Model::getInstanceById() call so again you can't really
>> extend the function because it has already been called. The only way is to
>> explicitly call your own custom method in your Record Model is to use
>> MyCustomModule_Record_Model::getInstanceById(). Which is what I am doing
>> for now.
>>
>> being able to pass a callback/method parameter to this at the vtiger
>> level might work for most situations, but not all as described above.
>>
>> Cheers
>>
>> Al
>> _______________________________________________
>> http://www.vtiger.com/
>>
>>
>> _______________________________________________
>> http://www.vtiger.com/
>
>
>
> --
> With
> Best Regards
> Uma.S
> Vtiger Team
> _______________________________________________
> http://www.vtiger.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20201211/b6535a59/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 80331 bytes
Desc: not available
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20201211/b6535a59/attachment-0001.png>


More information about the vtigercrm-developers mailing list