Iframe
extends BasicEntity
in package
Base class for ad-hoc entities that implement CRUD actions.
This is one of 3 possible base classes for an APIv4 Entity
(the others are DAOEntity
and AbstractEntity
).
This base class is for entities that do not have an associated DAO but do implement CRUD actions. It can be used in one of these ways:
- Extend this class and define the static variables
$getter
,$setter
&$deleter
with callbacks to handle CRUD operations. In that case there is no need to implement any actions other thangetFields
. - Override the
get
,create
,delete
, etc. methods with custom BasicAction implementations. - Some combination of the above two options, e.g. defining a callback for
$getter
and using the defaultget
action, but leaving$deleter
unset and overriding thedelete
method with a custom BasicBatchAction to handle deletion.
Note: the replace
action does not require any callback as it internally calls the entity's get
, save
and delete
actions.
Table of Contents
Properties
- $deleter : callable
- Function to delete records. Used by `delete` action.
- $getter : callable
- Function to read records. Used by `get` action.
- $setter : callable
- Function to write a record. Used by `create`, `update` and `save`.
Methods
- __callStatic() : AbstractAction
- Magic method to return the action object for an api.
- autocomplete() : AutocompleteAction
- checkAccess() : CheckAccessAction
- create() : BasicCreateAction
- delete() : BasicBatchAction
- get() : BasicGetAction
- getActions() : GetActions
- getEntityName() : string
- Get entity name from called class
- getFields() : BasicGetFieldsAction
- getInfo() : array{name: string, title: string, description: string, title_plural: string, type: string, paths: array, class: string, primary_key: array, searchable: string, dao: string, label_field: string, icon: string}
- Reflection function called by Entity::get()
- getLinks() : GetLinks
- installScript() : AbstractAction
- permissions() : array<string|int, mixed>
- Returns a list of permissions needed to access the various actions in this api.
- replace() : BasicReplaceAction
- save() : BasicSaveAction
- update() : BasicUpdateAction
- getDaoName() : CRM_Core_DAO|string|null
- getEntityTitle() : string
- Overridable function to return a localized title for this entity.
Properties
$deleter
Function to delete records. Used by `delete` action.
protected
static callable
$deleter
Function(array $item, BasicBatchAction $thisAction): array
This function is called once per delete. It takes a single record as the first param, and a reference to the action object as the second.
This callback should check the $idField of the item to determine which record to delete.
It should return the deleted record as an array.
$getter
Function to read records. Used by `get` action.
protected
static callable
$getter
Function(BasicGetAction $thisAction): array[]
This function should return an array of records, and is passed a copy of the BasicGetAction object as its first argument. The simplest implementation is for it to return every record and the BasicGetAction automatically handle sorting and filtering.
If performance is a concern, it can take advantage of some helper functions for e.g. fetching item(s) by id.
Tags
$setter
Function to write a record. Used by `create`, `update` and `save`.
protected
static callable
$setter
Function(array $item, BasicCreateAction|BasicSaveAction|BasicUpdateAction $thisAction): array
This function is called once per write. It takes a single record as the first param, and a reference to the action object as the second.
This callback should check the $idField of the record to determine whether the operation is a create or update.
It should return the updated record as an array.
Methods
__callStatic()
Magic method to return the action object for an api.
public
static __callStatic(string $action, array<string|int, mixed> $args) : AbstractAction
Parameters
- $action : string
- $args : array<string|int, mixed>
Tags
Return values
AbstractActionautocomplete()
public
static autocomplete([bool $checkPermissions = TRUE ]) : AutocompleteAction
Parameters
- $checkPermissions : bool = TRUE
Return values
AutocompleteActioncheckAccess()
public
static checkAccess() : CheckAccessAction
Return values
CheckAccessActioncreate()
public
static create([bool $checkPermissions = TRUE ]) : BasicCreateAction
Parameters
- $checkPermissions : bool = TRUE
Return values
BasicCreateActiondelete()
public
static delete([bool $checkPermissions = TRUE ]) : BasicBatchAction
Parameters
- $checkPermissions : bool = TRUE
Return values
BasicBatchActionget()
public
static get([bool $checkPermissions = TRUE ]) : BasicGetAction
Parameters
- $checkPermissions : bool = TRUE
Return values
BasicGetActiongetActions()
public
static getActions([bool $checkPermissions = TRUE ]) : GetActions
Parameters
- $checkPermissions : bool = TRUE
Return values
GetActionsgetEntityName()
Get entity name from called class
public
static getEntityName() : string
Return values
stringgetFields()
public
static getFields() : BasicGetFieldsAction
Return values
BasicGetFieldsActiongetInfo()
Reflection function called by Entity::get()
public
static getInfo() : array{name: string, title: string, description: string, title_plural: string, type: string, paths: array, class: string, primary_key: array, searchable: string, dao: string, label_field: string, icon: string}
Tags
Return values
array{name: string, title: string, description: string, title_plural: string, type: string, paths: array, class: string, primary_key: array, searchable: string, dao: string, label_field: string, icon: string}getLinks()
public
static getLinks([bool $checkPermissions = TRUE ]) : GetLinks
Parameters
- $checkPermissions : bool = TRUE
Return values
GetLinksinstallScript()
public
static installScript() : AbstractAction
Return values
AbstractActionpermissions()
Returns a list of permissions needed to access the various actions in this api.
public
static permissions() : array<string|int, mixed>
Return values
array<string|int, mixed>replace()
public
static replace([bool $checkPermissions = TRUE ]) : BasicReplaceAction
Parameters
- $checkPermissions : bool = TRUE
Return values
BasicReplaceActionsave()
public
static save([bool $checkPermissions = TRUE ]) : BasicSaveAction
Parameters
- $checkPermissions : bool = TRUE
Return values
BasicSaveActionupdate()
public
static update([bool $checkPermissions = TRUE ]) : BasicUpdateAction
Parameters
- $checkPermissions : bool = TRUE
Return values
BasicUpdateActiongetDaoName()
protected
static getDaoName() : CRM_Core_DAO|string|null
Return values
CRM_Core_DAO|string|nullgetEntityTitle()
Overridable function to return a localized title for this entity.
protected
static getEntityTitle([bool $plural = FALSE ]) : string
Parameters
- $plural : bool = FALSE
-
Whether to return a plural title.