This tutorial provides instructions for converting an entity from type Base to type Base Plus. I needed to do this recently and it took me a few minutes to figure it out. To document the process so it is easier next time, here is a tutorial.
Assumptions:
Edit the controller in Controllers/TestEntity.php. The following line needs to be modified:
Edit the language files in Resources/i18n/xx_xx/TestEntity.json. The following lines need to be added:
Edit the client definition in Resources/metadata/clientdefs/TestEntity.php. The following lines needs to be added:
Edit the scope definition in Resources/metadata/scopes/TestEntity.json. The following line needs to be modified:
Edit the entity definition in Resources/metadata/entityDefs/TestEntity.json. The following lines need to be added:
Edit the entity definition in Entities/TestEntity.php. The following line needs to be modified:
Edit the entity definition in Services/TestEntity.php. The following line needs to be modified:
Now is the part when you have to make a decision. The entity has to be added to the list of parent entities for each of the desired event entities. For example, to allow Meeting records to select TestEntity records as parents, modify the following file: custom/Espo/Custom/Resources/metadata/entityDefs/Meeting.json. Add the following code:
Do that for every entity which needs to select TestEntity records as the parent (Meetings, Calls, Tasks, etc.).
Rebuild in the administration menu. At this point, the entity should be the same as if it had been created as Base Plus instead of Base.
Assumptions:
- Files are located in custom/Espo/Custom/. If the files are in a module, replace that part of the path with custom/Espo/Modules/MyModule/. Nothing else is different.
- Meetings and Calls are the only event entities. If you have more types of event entities, add them to the lists whenever you see Meetings and Calls.
- Tasks are special. BasePlus entities have a relationship with Tasks by default, which typically means Tasks will appear in the same lists as Meetings and Calls. That is not always true, however, so be aware.
Edit the controller in Controllers/TestEntity.php. The following line needs to be modified:
Code:
class TestEntity extends \Espo\Core\Templates\Controllers\Base # Old class TestEntity extends \Espo\Core\Templates\Controllers\BasePlus # New
Code:
{ ... "links": { ... "meetings": "Meetings", "calls": "Calls", "tasks": "Tasks" }, ... }
Code:
{ ... "sidePanels": { "detail": [ { "name": "activities", "label": "Activities", "view": "crm:views/record/panels/activities", "aclScope": "Activities" }, { "name": "history", "label": "History", "view": "crm:views/record/panels/history", "aclScope": "Activities" }, { "name": "tasks", "label": "Tasks", "view": "crm:views/record/panels/tasks", "aclScope": "Task" } ] } }
Code:
"type": "Base" <-- Old "type": "BasePlus" <-- New
Edit the entity definition in Resources/metadata/entityDefs/TestEntity.json. The following lines need to be added:
Code:
{ ... "links": { ... "meetings": { "type": "hasMany", "entity": "Meeting", "foreign": "parent", "layoutRelationshipsDisabled": true }, "calls": { "type": "hasMany", "entity": "Call", "foreign": "parent", "layoutRelationshipsDisabled": true }, "tasks": { "type": "hasChildren", "entity": "Task", "foreign": "parent", "layoutRelationshipsDisabled": true }, "emails": { "type": "hasChildren", "entity": "Email", "foreign": "parent", "layoutRelationshipsDisabled": true } } }
Code:
class TestEntity extends \Espo\Core\Templates\Entities\Base # Old class TestEntity extends \Espo\Core\Templates\Entities\BasePlus # New
Edit the entity definition in Services/TestEntity.php. The following line needs to be modified:
Code:
class TestEntity extends \Espo\Core\Templates\Services\Base # Old class TestEntity extends \Espo\Core\Templates\Services\BasePlus # New
Now is the part when you have to make a decision. The entity has to be added to the list of parent entities for each of the desired event entities. For example, to allow Meeting records to select TestEntity records as parents, modify the following file: custom/Espo/Custom/Resources/metadata/entityDefs/Meeting.json. Add the following code:
Code:
{ ... "fields": { ... "parent": { "entityList": [ ... "TestEntity" ] } }, ... }
Rebuild in the administration menu. At this point, the entity should be the same as if it had been created as Base Plus instead of Base.
Comment