Skip to content

vtlib Enhancement request: Vtiger_Field API for JOIN to non-standard table

I'd like to be able to have some code in an extension module such that an administrator can choose via a UI option to add a special field to an existing module.

In this particular case I would like to be able to add two fields to show the Latitude and Longitude values from a different table, e.g. libertus_geotools

In the following code snippet, what I could do with would be an API to specify the join for this table, because I can't write/update the module's class file directly...

// Modulename could be any entity module, e.g. 'Accounts'

function addGeocodedFieldstoModule($moduleName) {
    include_once 'vtlib/Vtiger/Module.php';
    $module = Vtiger_Module::getInstance($moduleName);
    $allBlocks = Vtiger_Block::getAllForModule($module);
    // Get First Block
    $block = $allBlocks[0];

    $fields = array('lat' => 'Lattitude', 'lng' => 'Longitude');
    foreach ($fields as $name => $label) {
        $field = Vtiger_Field::getInstance($name, $module);
        if (!$field && $block) {
            $field = new Vtiger_Field();
            $field->name = 'ls'.$name;
            $field->column = $field->name;
            $field->table = 'libertus_geotools';
            $field->join = array('vtiger_crmentity.crmid' => 'libertus_geotools.crmid'); //<<< Something like this perhaps
            $field->label = $label;
            $field->columntype = 'FLOAT(10,6)';
            $field->uitype = 1;
            $field->typeofdata = 'V~O';
            $field->displaytype = 2; // Readonly
            $block->addField($field);
        }
    }
}