This tutorial describes how to create a simple extension based on a custom implementation and shows how to use 'Modules' to segregate customizations instead of having everything in the 'Custom' namespaces, making it much easier to manage changes and troubleshooting for your custom code.
The custom implementation described here is a button in an entity's detail display, that when clicked recalculates all formulas that apply to the subject entity.
Please follow this link to see the original scripts which I will use to describe what changes were made to turn it into an installable extension.
https://forum.espocrm.com/forum/gene...7904#post67904
The namespace that we will use for this example is "FormulaRefresh" for back-end code and "formula-refresh" for front-end code
Step 1:
Change the namespace reference in the original front-end script
client/custom/src/unrestricted-recalculate-formula-handler,js
from:
to:
Save the modified script (in your local machine) as:
files/client/modules/recalculate-formula/src/unrestricted-recalculate-formula-handler.js
Step 2:
Change the namespace reference in the back-end script:
custom/Espo/Custom/Controllers/RecalculateFormula.php
from:
to:
Save the modified script (in your local machine) as:
files/application/Espo/Modules/FormulaRefresh/Controllers/RecalculateFormula.php
Step 3:
Change the namespace reference in the back-end script:
custom/Espo/Custom/Services/RecalculateFormula.php
from:
to:
Save the modified script (in your local machine) as:
files/application/Espo/Modules/FormulaRefresh/Services/RecalculateFormula.php
Step 4:
Save the file custom/Espo/Custom/Resources/routes.json as files/application/Espo/Modules/FormulaRefresh/Resources/routes.json
Step 5:
Create file (in your local machine) files/application/Espo/Modules/FormulaRefresh/Resources/metadata/module.json where you will establish a hierarchy (the higher the number the higher hierarchy) in case of conflict with other namespaces. The official extension Real Estate for example has an "order" value of 15. The namespace "Custom" is always the highest hierarchy.
Step 6:
Create file (in your local machine) manifest.json where Espo will read the extension basic parameters to install properly
Step 7:
Compress the folder "files" and the file "manifest.json" as zip file "formula-refresh-for-espocrm-1.0.0.zip"
Congratulations !, you just created an installable extension which you can upload and install at Admin > Extensions
The custom implementation described here is a button in an entity's detail display, that when clicked recalculates all formulas that apply to the subject entity.
Please follow this link to see the original scripts which I will use to describe what changes were made to turn it into an installable extension.
https://forum.espocrm.com/forum/gene...7904#post67904
The namespace that we will use for this example is "FormulaRefresh" for back-end code and "formula-refresh" for front-end code
Step 1:
Change the namespace reference in the original front-end script
client/custom/src/unrestricted-recalculate-formula-handler,js
from:
Code:
define('custom:unrestricted-recalculate-formula-handler', ['action-handler'], function (Dep) { ...
Code:
define('[B]formula-refresh[/B]:unrestricted-recalculate-formula-handler', ['action-handler'], function (Dep) { ...
files/client/modules/recalculate-formula/src/unrestricted-recalculate-formula-handler.js
Step 2:
Change the namespace reference in the back-end script:
custom/Espo/Custom/Controllers/RecalculateFormula.php
from:
Code:
namespace Espo\Custom\Controllers; ...
Code:
namespace Espo\[B]Modules\FormulaRefresh[/B]\Controllers;
files/application/Espo/Modules/FormulaRefresh/Controllers/RecalculateFormula.php
Step 3:
Change the namespace reference in the back-end script:
custom/Espo/Custom/Services/RecalculateFormula.php
from:
Code:
namespace Espo\Custom\Services;
Code:
namespace Espo\[B]Modules\FormulaRefresh[/B]\Services; ...
files/application/Espo/Modules/FormulaRefresh/Services/RecalculateFormula.php
Step 4:
Save the file custom/Espo/Custom/Resources/routes.json as files/application/Espo/Modules/FormulaRefresh/Resources/routes.json
Step 5:
Create file (in your local machine) files/application/Espo/Modules/FormulaRefresh/Resources/metadata/module.json where you will establish a hierarchy (the higher the number the higher hierarchy) in case of conflict with other namespaces. The official extension Real Estate for example has an "order" value of 15. The namespace "Custom" is always the highest hierarchy.
Code:
{ "order": 20 }
Create file (in your local machine) manifest.json where Espo will read the extension basic parameters to install properly
Code:
{ "name": "Formula Refresh", "version": "1.0.0", "acceptableVersions": [ ">=6.1.1" ], "releaseDate": "2021-02-21", "author": "Omar A Gonsenheim", "description": "Gives any User with 'edit' privileges the ability to recalculate formulas by clicking a button on an entity's 'detail' display" }
Compress the folder "files" and the file "manifest.json" as zip file "formula-refresh-for-espocrm-1.0.0.zip"
Congratulations !, you just created an installable extension which you can upload and install at Admin > Extensions
Comment