Documentation

BasicEntity extends AbstractEntity
in package

AbstractYes

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:

  1. 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 than getFields.
  2. Override the get, create, delete, etc. methods with custom BasicAction implementations.
  3. Some combination of the above two options, e.g. defining a callback for $getter and using the default get action, but leaving $deleter unset and overriding the delete 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
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
see
BasicGetAction::getRecords()

$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

getEntityName()

Get entity name from called class

public static getEntityName() : string
Return values
string

getInfo()

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
inheritDoc
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}
public static getLinks([bool $checkPermissions = TRUE ]) : GetLinks
Parameters
$checkPermissions : bool = TRUE
Return values
GetLinks

permissions()

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>

getEntityTitle()

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.

Return values
string

        
On this page

Search results