public function replaceDefaultTypeMapper(): bool
{
return true;
}
Record mappers are classes that allow to add code for mapping a record to internal or to external format.
Mappers are have been added to allow for more flexibility when extending SuiteCRM.
They are split into levels, type and modes, there are:
Levels:
Api Mappers
Entity Mappers
Types:
Field
Field Type
Record
Modes:
retrieve
list
save
Mappers run at 2 levels, Api level and Entity level.
Mappers on the Api level is executed immediately before or after receiving or sending data to api.
There are multiple scenarios where you can use these: - When you want to modify the data before sending/receiving it to the API. - When you want to inject custom fields / date to the response that goes to the frontend.
Entity leve is called within Entity level operations, e.g.:
Retrieving a record.
Saving a record.
etc…​
Entity Mappers will run regardless if they are called from the API or elsewhere.
There are multiple scenarios where you can use these: - When you want to transform the internal format of fields to a different format. - When you want to modify the data before saving it to the database. - When you have fields that are dependent on other fields.
There are 3 types of mapper for Entity and Api:
Field Mappers are only executed for the specified module and field. This is useful when you want to modify the data of a specific field (e.g. phone_mobile
on Accounts).
Field type mappers are executed for all the fields of a given type and for the specified module. This is useful when you want to add a generic transformation to all fields of a given type (e.g. datetime
on Accounts).
Record Mappers is executed at the "record scope", it is possible to change any number of fields for module at the same time. This is useful when you want to modify multiple fields at the same time.
Mapper modes allow you to specify when the mapper should run. One or more of the following modes can be set: retrieve, list, save.
This mode is called when retrieving a single record, i.e. when calling the getRecord
entrypoint. Ex: when opening a record view.
The toInternal
method is never called for this mode.
This mode is called when retrieving a list of records, i.e. when calling the getRecordList
entrypoint. Ex: when opening a list view, subpanels or any list.
This mode is called when saving a record, i.e. when calling the saveRecord
entrypoint. Ex: when saving a record from the record view.
When adding a new Record Mapper you will have the getOrder
function to set the order/ priority in which the mappers run per mapper type.
To set a default mapper for any of the mapper types, when adding the mapper, return the key default
.
When adding new mappers, if there is already a default
set for that mapper type (field, field type and record),
and you wish to run a new mapper instead you will have to add:
public function replaceDefaultTypeMapper(): bool
{
return true;
}
This will run your new mapper and not the default mapper.
Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.