Creating a custom module in vTiger CRM from scratch involves several steps, including defining the database schema, creating the necessary files, and installing the module. Here is a detailed guide to help you create a custom module with its own table.
Step 1: Set Up Your Environment
- Backup: Take a backup of your current vTiger instance, including the database.
- Environment: Ensure you have a working vTiger CRM instance and access to the server.
Step 2: Define the Database Schema
- Create Tables: Create the necessary tables in the database for your custom module. For example, if your module is named “CustomModule”, you might create two tables:
vtiger_custommodule
andvtiger_custommodulecf
.
CREATE TABLE `vtiger_custommodule` (
`custommoduleid` int(11) NOT NULL AUTO_INCREMENT,
`customfield` varchar(255) NOT NULL,
PRIMARY KEY (`custommoduleid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `vtiger_custommodulecf` (
`custommoduleid` int(11) NOT NULL,
PRIMARY KEY (`custommoduleid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Step 3: Create the Basic Structure
- Folder Structure: Navigate to the
modules
directory in your vTiger installation and create a new folder for your custom module. For example, create a folder namedCustomModule
. - Module File: Inside your
CustomModule
folder, create a file namedCustomModule.php
. This file will contain the class for your module.
Step 4: Define the Module Class
In CustomModule.php
, define your module class:
<?php
include_once 'modules/Vtiger/CRMEntity.php';
class CustomModule extends CRMEntity {
public $table_name = 'vtiger_custommodule';
public $table_index= 'custommoduleid';
// Define the mandatory table for supporting custom fields.
public $customFieldTable = Array('vtiger_custommodulecf', 'custommoduleid');
// Define the list of tables related to this module.
public $tab_name = Array('vtiger_crmentity', 'vtiger_custommodule', 'vtiger_custommodulecf');
public $tab_name_index = Array(
'vtiger_crmentity' => 'crmid',
'vtiger_custommodule' => 'custommoduleid',
'vtiger_custommodulecf'=>'custommoduleid'
);
public $list_fields = Array (
'Custom Field' => Array('custommodule', 'customfield'),
'Assigned To' => Array('crmentity','smownerid')
);
public $list_fields_name = Array (
'Custom Field' => 'customfield',
'Assigned To' => 'assigned_user_id'
);
public $list_link_field = 'customfield';
public $search_fields = Array(
'Custom Field' => Array('custommodule', 'customfield')
);
public $search_fields_name = Array (
'Custom Field' => 'customfield'
);
public $popup_fields = Array ('customfield');
public $def_basicsearch_col = 'customfield';
public $def_detailview_recname = 'customfield';
public $mandatory_fields = Array('customfield', 'assigned_user_id');
public $default_order_by = 'customfield';
public $default_sort_order='ASC';
}
?>
Step 5: Create the Installation Script
Create an installation script to register your module. Create a file named manifest.xml
in the CustomModule
directory:
<?xml version="1.0"?>
<module>
<name>CustomModule</name>
<label>Custom Module</label>
<parent>Tools</parent>
<version>1.0</version>
<type>entity</type>
<php_version>5.2</php_version>
<dependencies>
<vtiger_version>7.0</vtiger_version>
</dependencies>
<tables>
<table>
<name>vtiger_custommodule</name>
<engine>InnoDB</engine>
<fields>
<field>
<name>custommoduleid</name>
<type>int</type>
<nullable>false</nullable>
<key>PRI</key>
<extra>auto_increment</extra>
</field>
<field>
<name>customfield</name>
<type>varchar</type>
<nullable>false</nullable>
<length>255</length>
</field>
</fields>
</table>
<table>
<name>vtiger_custommodulecf</name>
<engine>InnoDB</engine>
<fields>
<field>
<name>custommoduleid</name>
<type>int</type>
<nullable>false</nullable>
<key>PRI</key>
</field>
</fields>
</table>
</tables>
</module>
Step 6: Install the Module
- Upload the Folder: Upload your
CustomModule
folder to themodules
directory of your vTiger installation. - Install via vTiger: Log in to vTiger as an administrator, go to the Module Management section, and use the “Import Module” feature to upload and install your
CustomModule
.
Step 7: Configure the Module
- Create Fields: Use the Layout Editor in vTiger to add fields to your module as needed.
- Permissions: Set permissions for roles to access the new module.
Step 8: Test Your Module
- Verify Installation: Check that the module appears in the CRM and that you can create, view, edit, and delete records.
- Debug: If there are any issues, check the
vTiger.log
andPHP error logs
for troubleshooting.
Additional Customizations
Depending on your specific requirements, you might need to add more customizations, such as:
- Language Files: Create language files to support multiple languages.
- Custom Views: Create custom views for list and detail views.
- Workflow Integration: Integrate your module with vTiger workflows.
- Web Services: Enable web services for your custom module if needed.
By following these steps, you can create and configure a custom module in vTiger CRM with its own table.
Conclusion
Making the best custom module in vTiger CRM solutions initially from raw consists of numerous steps, consisting of describing the database schema, developing the important documents, and only installing the needed module. Here is a complete guide to help you develop a custom module with its individual table. Infinitive Host provides you the best vTiger hosting solutions that easily match your requirements.