Eblasoft | Cloning Entity In EspoCRM
top of page

Cloning Entity In EspoCRM

As we know EspoCRM already support four entity types (structure templates) for now:

  • Base.

  • Base Plus

  • Person.

  • Company.

But sometimes you may need to clone an existing entity including all related functionalities. For example you may want to duplicate the "Meeting" or "Call" ones, or even to duplicate custom entities definitions you made by your hand from one crm to another or in the same crm.

 

Let's say we want to clone the "Meeting" entity as example to a new entity names "Lesson",

- Create the new entity named "Lesson" from type "Base".

- Update Lesson controller:

path: /custom/Espo/Custom/Controllers/Lesson.php'
<?php

namespace Espo\Custom\Controllers;

use Espo\Modules\Crm\Controllers\Meeting;

class Lesson extends Meeting
{
}

- Update Lesson Repository:

Path: /custom/Espo/Custom/Repositories/Lesson.php

<?php

namespace Espo\Custom\Repositories;

use Espo\Modules\Crm\Repositories\Meeting;

class Lesson extends Meeting
{
}

- Update Lesson service file:

Path: /custom/Espo/Custom/Services/Lesson.php

<?php

namespace Espo\Custom\Services;

use Espo\Modules\Crm\Services\Meeting;

class Lesson extends Meeting
{
}

- Copy any Meeting.php files from `application` folder to `custom` folder, in our case we have these two files:

/application/Espo/Modules/Crm/SelectManagers/Meeting.php
/application/Espo/Modules/Crm/Acl/Meeting.php

Copy them to:

/custom/Espo/Custom/SelectManagers/Lesson.php /custom/Espo/Custom/Acl/Lesson.php

NOTE: don't forgot to replace 'Meeting' words occurrence with 'Lesson'

NOTE: change the namespaces as well to

namespace Espo\Custom\Acl;

- Resources JSON files:

open this file:

- application/Espo/Modules/Crm/Resources/i18n/en_US/Meeting.json

and copy its content to this one

- /custom/Espo/Custom/Resources/i18n/en_US/Lesson.json

copy `Meeting` layout folder

From:
application/Espo/Modules/Crm/Resources/layouts/Meeting
To:
custom/Espo/Custom/Resources/layouts/Lesson

Copy the following `Meeting` metadata files

application/Espo/Modules/Crm/Resources/metadata/clientDefs/Meeting.json
application/Espo/Modules/Crm/Resources/metadata/entityDefs/Meeting.json
application/Espo/Modules/Crm/Resources/metadata/scopes/Meeting.json
application/Espo/Modules/Crm/Resources/metadata/dashlets/Meeting.json

To:

custom/Espo/Custom/Resources/metadata/clientDefs/Meeting.json custom/Espo/Custom/Resources/metadata/entityDefs/Meeting.json custom/Espo/Custom/Resources/metadata/scopes/Meeting.json custom/Espo/Custom/Resources/metadata/dashlets/Meeting.json

Update Lesson scope file setting the module value to "Custom":

{
    "entity": true,
    "layouts": true,
    "tab": true,
    "acl": true,
    "aclPortal": "recordAllAccountContactOwnNo",
    "module": "Custom", <== update here from "Crm" to "Custom"
    "customizable": true,
    "importable": true,
    "notifications": true,
    "calendar": true,
    "activity": true,
    "object": true,
    "activityStatusList": ["Planned"],
    "historyStatusList": ["Held", "Not Held"],
    "statusField": "status"
}

You can find the Source Files here.

2,605 views0 comments
bottom of page