[Vtigercrm-developers] VTiger Extension Module create custom field for Accounts Module
Alan Lord
alanslists at gmail.com
Thu Nov 26 10:40:24 GMT 2015
A few comments on your vtlib code:
public function addKvkfield(){
$module = new Vtiger_Module(); // Not required
$module->name = 'Accounts'; // Not required
$module = $module->getInstance('Accounts'); // Not required
Just do:
$module = Vtiger_Module::getInstance('Accounts');
$blockInstance = new Vtiger_Block(); // Not required
$blockInstance->label = 'LBL_ACCOUNT_INFORMATION'; // Not required
$blockInstance =
$blockInstance->getInstance($blockInstance->label,$module); // Not required
Just do
$blockInstance = Vtiger_Block::getInstance('LBL_ACCOUNT_INFORMATION',
$module);
$fieldInstance = new Vtiger_Field();
$fieldInstance->name = 'KvKNummer'; // Should really only use
lowercase.
$fieldInstance->table = $module->basetable; // Not required (Chosen
by default)
$fieldInstance->column = 'kvknummer'; // Change to
$fieldInstance->column = fieldInstance->name;
$fieldInstance->columntype = 'VARCHAR(100)';
$fieldInstance->uitype = 2;
$fieldInstance->typeofdata = 'V~M';
$blockInstance->addField($fieldInstance);
}
So it will end up looking like this:
> public function addKvkfield(){
>
> $module = Vtiger_Module::getInstance('Accounts');
> $blockInstance = Vtiger_Block::getInstance('LBL_ACCOUNT_INFORMATION', $module);
>
> $fieldInstance = new Vtiger_Field();
> $fieldInstance->name = 'kvknummer';
> $fieldInstance->column = $fieldInstance->name; // Good idea to keep name and columnname the same
> $fieldInstance->columntype = 'VARCHAR(100)';
> $fieldInstance->uitype = 1; // No need to use 2 anymore. Setting "M" below will introduce the Red asterisk
> $fieldInstance->typeofdata = 'V~M';
> $blockInstance->addField($fieldInstance);
> }
More information about the vtigercrm-developers
mailing list