Line 58:
Line 58:
*Replace all occurrences of "modMyModule" with a value which corresponds to the purpose of your module. This value must always start with 'mod' and contain only alpha characters (again, if the name given to the file was 'NewName', then replace all "modMyModule" with "modNewName").
*Replace all occurrences of "modMyModule" with a value which corresponds to the purpose of your module. This value must always start with 'mod' and contain only alpha characters (again, if the name given to the file was 'NewName', then replace all "modMyModule" with "modNewName").
−
*Change the number in: $this->numero = 100000 by a number that designates your module id. To avoid conflicts with other modules, you can consult the page that lists already reserved id numbers: [[List of modules id|List of modules id]].
+
*Change the number in: $this->numero = 100000 by a number that designates your module id. To avoid conflicts with other modules, you can consult the page that lists already reserved id numbers: [[List of modules id|List of module IDs]].
*Modify any other variables defined in the constructor (see comment in the code skeleton for their meaning).
*Modify any other variables defined in the constructor (see comment in the code skeleton for their meaning).
Line 198:
Line 198:
</syntaxhighlight>
</syntaxhighlight>
−
'''4. show tabs into your page'''
+
'''4. show tabs on your page'''
−
Use function dol_fiche_head() to show all tabs defined into array $head returned by XX_prepare_head().
+
Use the <code>dol_fiche_head()</code> function to show all tabs defined in the <code>$head</code> array returned by <code>XX_prepare_head()</code>.
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 272:
Line 272:
You may want to provide a module that adds more fields into forms (input and view) of some elements.
You may want to provide a module that adds more fields into forms (input and view) of some elements.
−
A heavy solution (but not so bad) may be to replace all pages used to create element (this means to disable the "New element" menu entry and adding yours, and disable tab that shows element to replace with a tab that is your own full page (copied/pasted from original) to do same than original page but modified to add your fields and stored added data into your own table). Go to menu [[#Define your entries in the menu (optional)]] and [[#The tab management (optional)]] if this solution suits you (this solution is more powerful since you can change everything you want into the page).
+
A heavy solution (but not so bad) may be to replace all pages used to create element (this means disabling the "New element" menu entry and adding yours, and disabling the tab that shows the element to replace with a tab that is your own full page (copied/pasted from original) to do same than original page but modified to add your fields and stored added data into your own table). Go to menu [[#Define your entries in the menu (optional)]] and [[#The tab management (optional)]] if this solution suits you (this solution is more powerful since you can change everything you want into the page).
We will describe here another solution, that works only to "add fields" at end of existing fields, using the element "category" as an example but you can convert this tutorial for invoice, proposal ...
We will describe here another solution, that works only to "add fields" at end of existing fields, using the element "category" as an example but you can convert this tutorial for invoice, proposal ...
−
*First thing is to add a table, owned by your module, to store the value of new fields. This table will have only one column called "rowid" (will contain the same value than field rowid of element table) + one column for each new field you want to add. Then create a class with CRUD (Create/Read/Update/Delete) methods for this new table. For this two tasks, go back to previous chapter [[#Create your SQL tables and the PHP DAO class]].
+
*First thing is to add a table, owned by your module, to store the value of new fields. This table will only have one column called <code>rowid</code> (will contain the same value as the <code>rowid</code> column in the element table) + one column for each new field you want to add. Then, create a class with CRUD (Create/Read/Update/Delete) methods for this new table. For those two tasks, go back to the previous chapter [[#Create your SQL tables and the PHP DAO class (optional)]].
*Next step is to add a hook into your module to add the new fields into the form. See chapter [[Hooks_system#Implement_the_Hook]] for generic documentation to use hooks.
*Next step is to add a hook into your module to add the new fields into the form. See chapter [[Hooks_system#Implement_the_Hook]] for generic documentation to use hooks.
Line 381:
Line 381:
Go into page '''Home->Setup->Modules''', you should see a picture at the end of the line of your module to reach your setup page. Click on it, you should be able to view/edit parameters from your page.
Go into page '''Home->Setup->Modules''', you should see a picture at the end of the line of your module to reach your setup page. Click on it, you should be able to view/edit parameters from your page.
−
==Define your entries in menu (optional)==
+
==Define your entries in the menu (optional)==
'''When''': If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu.
'''When''': If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu.
Line 501:
Line 501:
==Define your CSS styles (optional)==
==Define your CSS styles (optional)==
−
'''When''': If in your PHP pages, you use class styles that are not defined inside Dolibarr themes CSS (not recommanded).
+
'''When''': If in your PHP pages, you use class styles that are not defined inside Dolibarr themes CSS (not recommended).
===Create and declare your style sheet===
===Create and declare your style sheet===
Line 508:
Line 508:
Once your style sheets are ready, declare them into your module descriptor file by modifying the property '''$this->modules_parts'''.
Once your style sheets are ready, declare them into your module descriptor file by modifying the property '''$this->modules_parts'''.
−
Value to put here must be an array of relative URLs to your CSS files.
+
Value to put here must be an array of relative URLs of your CSS files.
For example
For example
<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 519:
Line 519:
Go on the home page (index.php). Show the HTML source of the page.
Go on the home page (index.php). Show the HTML source of the page.
−
You should see into the HTML header, a line that declares your style sheet.
+
In the HTML header, you should see a line that declares your style sheet.
−
==Add your Javascript functions (optional)==
+
==Add your JavaScript functions (optional)==
'''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js)
'''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js)
−
If you need to use your own javascript functions inside your PHP pages, it is necessary to have your functions, defined into your javascript file '''htdocs/mymodule/js/mymodule.js''', included into the HTML HEAD section.
+
If you need to use your own JavaScript functions inside your PHP pages, it is necessary to define your functions in your JavaScript file '''htdocs/mymodule/js/mymodule.js''', included in the HTML <code><head/></code> section.
−
To ask Dolibarr that forge this header to include your own javascript file, you must just provide it to the llxHeader() function called by your page.
+
Dolibarr is responsible for building that HTML section. In order to ask it to include your JavaScript file, you just need to provide it to the llxHeader() function called by your page.
Example for page /htdocs/mymodule/mypage.php :
Example for page /htdocs/mymodule/mypage.php :
Line 534:
Line 534:
==Run your own code on any Dolibarr event (optional)==
==Run your own code on any Dolibarr event (optional)==
−
'''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''triggers'''.
+
'''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''trigger'''.
See also [[Interfaces_Dolibarr_toward_foreign_systems]]
See also [[Interfaces_Dolibarr_toward_foreign_systems]]
Line 551:
Line 551:
==Add your document template (optional)==
==Add your document template (optional)==
−
'''When''': When you want to personalized your own generated PDF or ODT documents.
+
'''When''': When you want to personalize your own generated PDF or ODT documents.
−
Note: To add this feature you don't need to create a module descriptor.
+
Note: To add this feature, you don't need to create a module descriptor.
Documentation to add your own template is available on page [[Create_a_PDF_document_template]] or [[Create_an_ODT_document_template]].
Documentation to add your own template is available on page [[Create_a_PDF_document_template]] or [[Create_an_ODT_document_template]].
Line 560:
Line 560:
'''When''': When you want to personalized your colors/fonts/images.
'''When''': When you want to personalized your colors/fonts/images.
−
Note: To add this feature you don't need to create a module descriptor.
+
Note: To add this feature, you don't need to create a module descriptor.
To add your own skin, read page [[Skins]].
To add your own skin, read page [[Skins]].
Line 590:
Line 590:
</syntaxhighlight>
</syntaxhighlight>
−
*If you want your module to be public, you can submit it (the zip file) on Dolibarr marketplace website: {{LinkToPluginDownload}} (you must create an account first and be logged to use the link "Submit a module/product").
+
*If you want your module to be public, you can submit it (the zip file) on the Dolibarr marketplace website: {{LinkToPluginDownload}} (you must first create an account and be logged in to use the "Submit a module/product" link).
**If your module was built correctly, the file will be validated later.
**If your module was built correctly, the file will be validated later.
−
**If quality is enough and license permits it, the code might be added inside main Dolibarr sources (except if you disagree for that).
+
**If quality is sufficient and license permits it, the code might be added inside main Dolibarr sources (except if you disagree for that).
=Enabling/activation condition of external module on DoliStore=
=Enabling/activation condition of external module on DoliStore=