Announcement

Collapse
No announcement yet.

Coding Tutorial: How to package a custom implementation as an installable extension.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • espcrm
    commented on 's reply
    "I felt totally ignorant trying to follow the documentation instructions"

    Hello fellow friend

  • item
    commented on 's reply
    Hello Emillod, +1 like telecastg ..

  • telecastg
    replied
    Originally posted by emillod View Post
    Hello guys!
    I've try to manage extensions for many months, but it's hard to do so without template. I've tried to build extensions, but it take a lot of time
    So i think that if you want to create extension, you should use ext-template repo from EspoCRM: https://github.com/espocrm/ext-template
    It's pretty simple. You have to prepare environment on your computer or server, but it's simple.
    Hello emillod !

    I must confess that not being a professional developer, I felt totally ignorant trying to follow the documentation instructions.

    If you have time could you post an example of an actual use of this template ? So far I have been building our modules purely by hand and it works fine, but if using the template can simplify the process it would be great.

    Thanks in advance !

    Leave a comment:


  • emillod
    replied
    Hello guys!
    I've try to manage extensions for many months, but it's hard to do so without template. I've tried to build extensions, but it take a lot of time
    So i think that if you want to create extension, you should use ext-template repo from EspoCRM: https://github.com/espocrm/ext-template
    It's pretty simple. You have to prepare environment on your computer or server, but it's simple.

    item in regard to your question about composer package.
    1. Prepare propper structure for your extension. That's mean you have to prepare module for your ext in app folder. For example \files\application\Espo\Modules\OvhIntegration\
    2. In module folder(\files\application\Espo\Modules\OvhIntegrat ion\) Create composer.json for example: https://pastebin.com/NELatsmD
    3. In module Resource directory, create file autoload.json with path to autoload.php: https://pastebin.com/ar0X7Udy
    4. Open CLI in module folder and run composer install to make sure that your extension will have propper packages attached
    5. Enjoy

    After that you don't have to attach vendor in any file, just use package.
    If you want i can attach package with composer as an example.
    Of course also please let me know if you'll have any questions

    Leave a comment:


  • telecastg
    replied
    Hello friend,

    As I mentioned I don't know much about composer so I don't know how to incorporate it in a custom extension.

    My only experience thus far with external libraries in a custom extension, is what I did with the esignature documents extension https://github.com/telecastg/esignat...ts-for-espocrm (please download the zip file and open it locally to better understand what I mean).

    In that case I used the "jsignature" library to create and manage the signature panel, so I used a folder files/client/modules/esignature/lib/jsignature/ to store all the jsignature library files and folders, and then created the file files/application/Espo/Modules/Esignature/Resources/metadata/app/client.json to call all scripts under the lib folder.

    However, in my case I was incorporating a front-end library and in your case you would need to incorporate a back-end library and I don't know which metadata script you would use for that.

    Perhaps emillod or eymen-elkum or yuri or Maximus can help.
    Last edited by telecastg; 02-24-2021, 01:32 AM.

    Leave a comment:


  • item
    replied
    Hello friend,
    i have voip extension.. and there are a vendor library.. (same path as you write..like espocrm out-of-box vendor but for module )
    but with one file : autoload.php .. with content :

    PHP Code:
    <?php
    // autoload.php @generated by Composer
    require_once __DIR__ '/composer/autoload_real.php';
    return 
    ComposerAutoloaderInitBBBBBBBSSSDDDD::getLoader();
    I don't know how is "generate".. and how it's "_append" .. you understand me because i don't understand

    I think i have no post anything "confidential" .. and replace some char with "BBBBSSSDD"

    Regards

    Leave a comment:


  • telecastg
    replied
    You're very welcome item , don't know about legend though, there are a lot of very good coders / developers here aside from the more active that we all know, they just might be a little shy (or maybe selfish) to post code examples that benefit everyone

    Regarding your first question: We used a custom route for this example because the controller and service classes are not part of an entity and by using a custom route you can direct Espo to the correct controller and action instead of following the general API call to Controller(same name as entity)/action.

    You don't need to create custom routes if all your back end controllers are derived from a record, as it is most common.

    Regarding the second question I am afraid that I am a complete new comer to composer so I don't know the answer...
    Last edited by telecastg; 02-23-2021, 01:25 AM.

    Leave a comment:


  • item
    replied
    Thanks friend.. you are the legend ( emillod now you know the real legend )
    Next step, with custom library (vendor.. autoload field how make with composer in new extension/module )

    question :
    - why we need route.json ?
    - can i extension use out-of-box Util ? certainly.. but for be sure.

    Leave a comment:


  • Coding Tutorial: How to package a custom implementation as an installable extension.

    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:
    Code:
    define('custom:unrestricted-recalculate-formula-handler', ['action-handler'], function (Dep) {
    ...
    to:
    Code:
    define('[B]formula-refresh[/B]:unrestricted-recalculate-formula-handler', ['action-handler'], function (Dep) {
    ...
    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:

    Code:
    namespace Espo\Custom\Controllers;
    ...
    to:
    Code:
    namespace Espo\[B]Modules\FormulaRefresh[/B]\Controllers;
    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:
    Code:
    namespace Espo\Custom\Services;
    to:
    Code:
    namespace Espo\[B]Modules\FormulaRefresh[/B]\Services;
    ...
    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.
    Code:
    {
        "order": 20
    }
    Step 6:
    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"
    }
    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
    Last edited by telecastg; 02-24-2021, 05:40 AM.
Working...
X