0

I need to create a custom module in vTiger, but it should have all kind of variations in terms of field data types, default values, dependent picklists, relation fields [UI Type 10], etc.

I have installed the latest stable version of vTiger7, but I'm unable to start the entry point of this code, so let me know how to start.

karel
  • 5,489
  • 46
  • 45
  • 50
P P
  • 49
  • 10
  • Use console to create the module, then create fields from vtiger ui. Guide to creating a module from command line https://community.vtiger.com/help/vtigercrm/developers/vtlib/console-tool.html – CommandMasterChiefDK Feb 28 '20 at 20:18

2 Answers2

1

Here is script where you can create new custom module in vTiger7. Keep Coding!!

You need to execute this script through url.

 <?php

include_once 'vtlib/Vtiger/Module.php';
include_once 'vtlib/Vtiger/Package.php';
include_once 'includes/main/WebUI.php';

include_once 'include/Webservices/Utils.php';

$Vtiger_Utils_Log = true;

$MODULENAME = 'CustomModule';

$moduleInstance = new Vtiger_Module();
$moduleInstance->name = $MODULENAME;
$moduleInstance->parent = "Tools";
$moduleInstance->save();

// Schema Setup
$moduleInstance->initTables();

// Webservice Setup
$moduleInstance->initWebservice();

// Field Setup
$block1 = new Vtiger_Block();
$block1->label = 'LBL_' . strtoupper($moduleInstance->name) . '_INFORMATION';
$moduleInstance->addBlock($block1);


// Filter Setup
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$moduleInstance->addFilter($filter1);

// Add field here using normal defination

$field = new Vtiger_Field();
$field->name = 'custom_name';
$field->table = $moduleInstance->basetable;
$field->label = 'Custom Name';
$field->column = $field->name;
$field->columntype = 'VARCHAR(100)';
$field->uitype = 1;
$field->displaytype = 1;
$field->presence = 2;
$field->typeofdata = 'V~M';
$block1->addField($field);
$filter1->addField($field, 2);

$field = new Vtiger_Field();
$field->name = 'assigned_user_id';
$field->label = 'Assigned To';
$field->table = 'vtiger_crmentity'; 
$field->column = 'smownerid';
$field->uitype = 53;
$field->displaytype = 1;
$field->presence = 2;
$field->typeofdata = 'V~M';
$block1->addField($field);

$field = new Vtiger_Field();
$field->name = 'createdtime';
$field->label = 'Created Time';
$field->table = 'vtiger_crmentity';
$field->column = 'createdtime';
$field->displaytype = 2;
$field->uitype = 70;
$field->typeofdata = 'D~O';
$block1->addField($field);

$field = new Vtiger_Field();
$field->name = 'modifiedtime';
$field->label = 'Modified Time';
$field->table = 'vtiger_crmentity';
$field->column = 'modifiedtime';
$field->displaytype = 2;
$field->uitype = 70;
$field->typeofdata = 'D~O';
$block1->addField($field);

// Sharing Access Setup
$moduleInstance->setDefaultSharing('Public');

$targetpath = 'modules/' . $moduleInstance->name;

if (! is_file($targetpath)) {
    mkdir($targetpath);

    $templatepath = 'vtlib/ModuleDir/6.0.0';

    $moduleFileContents = file_get_contents($templatepath . '/ModuleName.php');
    $replacevars = array(
        'ModuleName' => $moduleInstance->name,
        '<modulename>' => strtolower($moduleInstance->name),
        '<entityfieldlabel>' => $field1->label,
        '<entitycolumn>' => $field1->column,
        '<entityfieldname>' => $field1->name
    );

    foreach ($replacevars as $key => $value) {
        $moduleFileContents = str_replace($key, $value, $moduleFileContents);
    }
    file_put_contents($targetpath . '/' . $moduleInstance->name . '.php', $moduleFileContents);
}

if (! file_exists('languages/en_us/ModuleName.php')) {
    $ModuleLanguageContents = file_get_contents($templatepath . '/languages/en_us/ModuleName.php');

    $replaceparams = array(
        'Module Name' => $moduleInstance->name,
        'Custom' => $moduleInstance->name,
        'ModuleBlock' => $moduleInstance->name,
        'ModuleFieldLabel Text' => $field1->label
    );

    foreach ($replaceparams as $key => $value) {
        $ModuleLanguageContents = str_replace($key, $value, $ModuleLanguageContents);
    }

    $languagePath = 'languages/en_us';
    file_put_contents($languagePath . '/' . $moduleInstance->name . '.php', $ModuleLanguageContents);
}

Settings_MenuEditor_Module_Model::addModuleToApp($moduleInstance->name, $moduleInstance->parent);

echo $moduleInstance->name." is Created";

?>
Sachin I
  • 1,500
  • 3
  • 10
  • 29
  • Hello thank you for reply. May i know the where is put this code ? there is any path ?i have just make a php file and paste code in module folder. After that is showing error ' Fatal error: Uncaught Error: Class 'Vtiger_Block' not found in D:\xampp\htdocs\vtigercrm\modules\module.php:3 Stack trace: #0 {main} thrown in D:\xampp\htdocs\vtigercrm\modules\module.php on line 3' – P P Apr 16 '19 at 05:18
  • I think you are pretty new in vTiger development. This code is for to create new custom module in vTiger7. This file needs to save in root directory of vTiger and execute it. – Sachin I Apr 16 '19 at 05:28
  • Can you provide me some instructions to create custom module steps. I am not getting from above code. – P P Apr 16 '19 at 06:04
  • I have updated script as per your requirement just because you are new in vTiger. Please copy and execute this code through url. Save this file in root dir of crm. It will create new module. Thanks! – Sachin I Apr 16 '19 at 14:42
  • What is next steps to create modules after executing above codes?It is possible to create modules with structure like view,modules,languages ...?Can we export it in zip to import in another setups? – Satish Jun 08 '20 at 07:52
0

Use free modules like Vtiger Module Builder. these modules use vtlib libary and you can create new modules through Vtiger UI.

Hamid
  • 378
  • 3
  • 8