Adding a new module to vtiger CRM by coding involves several steps. vtiger is built on PHP and follows a modular architecture, so creating a new module means creating the necessary files, database tables, and configurations.
Here’s a high-level overview and a basic example of how to add a new module programmatically:
Step 1: Understand vtiger Module Structure
A vtiger module typically consists of:
Module files: PHP classes for the module’s business logic.
Language files: For labels and translations.
Database tables: To store module data.
Metadata files: To define fields, blocks, and layouts.
Menu entries: To add the module to the vtiger UI.
Step 2: Use vtiger’s Module Manager or Module Builder (Recommended)
Before coding manually, vtiger provides a Module Builder in the UI to create modules easily. But if you want to do it by code, continue below.
Step 3: Create the Module Programmatically
vtiger provides a PHP class called Vtiger_Module to create modules programmatically.
Example: Create a simple module called "Books"
php
<?php
include_once 'vtlib/Vtiger/Module.php';
// Create a new module instance
$module = new Vtiger_Module();
$module->name = 'Books';
// Save the module (this creates the module and database tables)
$module->save();
// Add a block (a section in the module layout)
$block = new Vtiger_Block();
$block->label = 'LBL_BOOK_INFORMATION';
$module->addBlock($block);
// Add fields to the block
$field1 = new Vtiger_Field();
$field1->name = 'book_title';
$field1->label= 'Book Title';
$field1->uitype = 2; // Text field
$field1->column = 'book_title';
$field1->columntype = 'VARCHAR(255)';
$field1->typeofdata = 'V~M'; // Varchar, Mandatory
$block->addField($field1);
$field2 = new Vtiger_Field();
$field2->name = 'author';
$field2->label= 'Author';
$field2->uitype = 2; // Text field
$field2->column = 'author';
$field2->columntype = 'VARCHAR(255)';
$field2->typeofdata = 'V~O'; // Varchar, Optional
$block->addField($field2);
// Add the module to the menu
$module->initWebservice();
$module->setRelatedList('Contacts', 'Contacts', array('ADD'), 'get_dependents_list');
echo "Module 'Books' created successfully.";
?>
Step 4: Place the Script and Run It
Save the above script as create_books_module.php in your vtiger root directory.
Run it via CLI or browser (make sure you have proper permissions and backup your system):
bash
php create_books_module.php
Step 5: Verify the Module
Log in to vtiger CRM.
Check the menu for the new "Books" module.
Try creating a new record.
Notes and Best Practices
Backup your database before running scripts that modify schema.
Use vtlib classes (Vtiger_Module, Vtiger_Block, Vtiger_Field) to ensure compatibility.
You can add more complex fields, relations, and workflows by extending this approach.
For production, package your module as a vtiger extension (ZIP with manifest) for easy installation.
Refer to vtiger’s developer documentation and existing modules for examples.
If you want, I can help you generate a more complex module or package it as an installable extension. Just ask!