GetAfforms
extends BasicBatchAction
in package
Get dynamic afforms for a custom group.
For single value custom groups we generate:
- a field block with all of the fields from the group
- a submission form for editing these fields on a parent entity record
For multi-value custom groups we generate:
- a field block with all of the fields from the group
- a submission form for adding a new Custom record to a parent entity record
- a submission form for editing a particular Custom record
- (not implemented yet) a search form for viewing all the Custom records
Table of Contents
Constants
- FORM_TYPES = ['afblockCustom', 'afformUpdateCustom', 'afformCreateCustom', 'afformViewCustom', 'afsearchTabCustom']
Properties
- $_debugOutput : mixed
- $_actionName : string
- $_entityName : string
- $chain : array<string|int, mixed>
- Additional api requests - will be called once per result.
- $checkPermissions : bool
- Whether to enforce acl permissions based on the current user.
- $debug : bool
- Add debugging info to the api result.
- $formTypes : array<string|int, mixed>
- Limit to generating specific afform types
- $getLayout : bool
- Whether to generate the form layouts
- $language : string
- Preferred language (optional)
- $limit : int
- Maximum number of $ENTITIES to return.
- $offset : int
- Zero-based index of first $ENTITY to return.
- $orderBy : array<string|int, mixed>
- Array of field(s) to use in ordering the results.
- $version : int
- Api version number; cannot be changed.
- $where : array<string|int, mixed>
- Criteria for selecting $ENTITIES to process.
Methods
- __call() : static|mixed
- Magic function to provide automatic getter/setter for params.
- __construct() : mixed
- BasicBatchAction constructor.
- __set() : mixed
- Strictly enforce api parameters
- _run() : mixed
- Checks permissions and then delegates to processBatch.
- addChain() : $this
- addClause() : $this
- Adds one or more AND/OR/NOT clause groups
- addOrderBy() : $this
- Adds to the orderBy clause
- addWhere() : $this
- entityFields() : array<string|int, mixed>
- Returns schema fields for this entity & action.
- evaluateCondition() : bool
- This function is used internally for evaluating field annotations.
- execute() : Result
- Invoke api call.
- getActionName() : string
- getChain() : array<string|int, mixed>
- getCheckPermissions() : bool
- getCustomGroupAfforms() : mixed
- getDebug() : bool
- getEntityName() : string
- getLanguage() : string|null
- getLimit() : int
- getOffset() : int
- getOrderBy() : array<string|int, mixed>
- getParamInfo() : array<string|int, mixed>
- Get documentation for one or all params
- getParams() : array<string|int, mixed>
- Serialize this object's params into an array
- getPermissions() : array<string|int, mixed>
- getWhere() : array<string|int, mixed>
- offsetExists() : bool
- offsetGet() : mixed
- offsetSet() : void
- offsetUnset() : void
- paramExists() : bool
- reflect() : ReflectionClass
- setChain() : $this
- setCheckPermissions() : $this
- setDebug() : $this
- setLanguage() : $this
- setLimit() : $this
- setOffset() : $this
- setOrderBy() : $this
- setVersion() : $this
- setWhere() : $this
- addCallbackToDebugOutput() : mixed
- When in debug mode, this logs the callback function being used by a Basic*Action class.
- checkRequiredFields() : array<string|int, mixed>
- Validates required fields for actions which create a new object.
- doTask() : array<string|int, mixed>
- This Basic Batch class can be used in one of two ways:
- formatWriteValues() : mixed
- Replaces pseudoconstants in input values
- getBatchAction() : AbstractGetAction
- Get an API action object which resolves the list of records for this batch.
- getBatchRecords() : array<string|int, mixed>
- Get a list of records for this batch.
- getLanguageOptions() : array<string|int, mixed>
- Get available preferred languages.
- getMagicProperties() : array<string|int, mixed>
- Get a list of class properties for which magic methods are supported.
- getParamDefaults() : array<string|int, mixed>
- getSelect() : array<string|int, string>
- Determines what fields will be returned by getBatchRecords
- parseGroupNameFromFormName() : string|null
- For afform base name, get the custom group name it corresponds to Or null if none
- parseGroupNamesFromAfformGetNames() : array<string|int, mixed>
- processBatch() : mixed
- Calls doTask once per item and stores the result.
- reloadResults() : array<string|int, mixed>
- whereClauseToString() : string
- Produces a human-readable where clause, for the reading enjoyment of you humans.
- generateCreateForm() : array<string|int, mixed>
- generateFieldBlock() : array<string|int, mixed>
- generateTabForm() : array<string|int, mixed>
- generateUpdateForm() : array<string|int, mixed>
- generateViewForm() : array<string|int, mixed>
Constants
FORM_TYPES
protected
mixed
FORM_TYPES
= ['afblockCustom', 'afformUpdateCustom', 'afformCreateCustom', 'afformViewCustom', 'afsearchTabCustom']
Properties
$_debugOutput
public
mixed
$_debugOutput
= []
$_actionName
protected
string
$_actionName
$_entityName
protected
string
$_entityName
$chain
Additional api requests - will be called once per result.
protected
array<string|int, mixed>
$chain
= []
Keys can be any string - this will be the name given to the output.
You can reference other values in the api results in this call by prefixing them with $.
For example, you could create a contact and place them in a group by chaining the
GroupContact api to the Contact api:
Contact::create()
->setValue('first_name', 'Hello')
->addChain('add_a_group', GroupContact::create()
->setValue('contact_id', '$id')
->setValue('group_id', 123)
)
This will substitute the id of the newly created contact with $id.
$checkPermissions
Whether to enforce acl permissions based on the current user.
protected
bool
$checkPermissions
= TRUE
Setting to FALSE will disable permission checks and override ACLs. In REST/javascript this cannot be disabled.
$debug
Add debugging info to the api result.
protected
bool
$debug
= FALSE
When enabled, $result->debug will be populated with information about the api call,
including sql queries executed.
Note: with checkPermissions enabled, debug info will only be returned if the user has "view debug output" permission.
$formTypes
Limit to generating specific afform types
protected
array<string|int, mixed>
$formTypes
= ['block', 'form', 'search']
Default to all
$getLayout
Whether to generate the form layouts
protected
bool
$getLayout
= FALSE
$language
Preferred language (optional)
protected
string
$language
This option will notify major localization subsystems (ts(), multilingual, etc)
about which locale should be used for composing/formatting messaging.
This indicates the preferred language. The effective language is determined
by Civi\Core\Locale::negotiate($preferredLanguage).
Tags
$limit
Maximum number of $ENTITIES to return.
protected
int
$limit
= 0
Defaults to 0 - unlimited.
Note: the Api Explorer sets this to 25 by default to avoid timeouts.
Change or remove this default for your application code.
$offset
Zero-based index of first $ENTITY to return.
protected
int
$offset
= 0
Defaults to 0 - first $ENTITY found.
$orderBy
Array of field(s) to use in ordering the results.
protected
array<string|int, mixed>
$orderBy
= []
Defaults to id ASC
$example->addOrderBy('sort_name', 'ASC')
$version
Api version number; cannot be changed.
protected
int
$version
= 4
$where
Criteria for selecting $ENTITIES to process.
protected
array<string|int, mixed>
$where
= []
Tags
Methods
__call()
Magic function to provide automatic getter/setter for params.
public
__call(mixed $name, mixed $arguments) : static|mixed
Parameters
- $name : mixed
- $arguments : mixed
Tags
Return values
static|mixed__construct()
BasicBatchAction constructor.
public
__construct(string $entityName, string $actionName[, callable $doer = null ]) : mixed
$myAction = new BasicBatchAction($entityName, $actionName, function($item) {
// Do something with $item
$return $item;
});
Parameters
- $entityName : string
- $actionName : string
- $doer : callable = null
__set()
Strictly enforce api parameters
public
__set(mixed $name, mixed $value) : mixed
Parameters
- $name : mixed
- $value : mixed
Tags
_run()
Checks permissions and then delegates to processBatch.
public
_run(Result $result) : mixed
Note: Unconditional logic must go here in the run function, as delegated functions may be overridden.
Parameters
- $result : Result
addChain()
public
addChain(string $name, AbstractAction $apiRequest[, string|int|array<string|int, mixed> $index = null ]) : $this
Parameters
- $name : string
-
Unique name for this chained request
- $apiRequest : AbstractAction
- $index : string|int|array<string|int, mixed> = null
-
See
civicrm_api4()for documentation of$indexparam
Return values
$thisaddClause()
Adds one or more AND/OR/NOT clause groups
public
addClause(string $operator, mixed $condition1) : $this
Parameters
- $operator : string
- $condition1 : mixed
-
... $conditionN Either a nested array of arguments, or a variable number of arguments passed to this function.
Tags
Return values
$thisaddOrderBy()
Adds to the orderBy clause
public
addOrderBy(string $fieldName[, string $direction = 'ASC' ]) : $this
Parameters
- $fieldName : string
- $direction : string = 'ASC'
Return values
$thisaddWhere()
public
addWhere(string $fieldName, string $op[, mixed $value = null ]) : $this
Parameters
- $fieldName : string
- $op : string
- $value : mixed = null
Tags
Return values
$thisentityFields()
Returns schema fields for this entity & action.
public
entityFields() : array<string|int, mixed>
Here we bypass the api wrapper and run the getFields action directly. This is because we DON'T want the wrapper to check permissions as this is an internal op.
Tags
Return values
array<string|int, mixed>evaluateCondition()
This function is used internally for evaluating field annotations.
public
static evaluateCondition(string $expr, array<string|int, mixed> $vars) : bool
It should never be passed raw user input.
Parameters
- $expr : string
-
Conditional in php format e.g. $foo > $bar
- $vars : array<string|int, mixed>
-
Variable name => value
Tags
Return values
boolexecute()
Invoke api call.
public
execute() : Result
At this point all the params have been sent in and we initiate the api call & return the result. This is basically the outer wrapper for api v4.
Tags
Return values
ResultgetActionName()
public
getActionName() : string
Return values
stringgetChain()
public
getChain() : array<string|int, mixed>
Return values
array<string|int, mixed>getCheckPermissions()
public
getCheckPermissions() : bool
Return values
boolgetCustomGroupAfforms()
public
static getCustomGroupAfforms(mixed $event) : mixed
Parameters
- $event : mixed
getDebug()
public
getDebug() : bool
Return values
boolgetEntityName()
public
getEntityName() : string
Return values
stringgetLanguage()
public
getLanguage() : string|null
Return values
string|nullgetLimit()
public
getLimit() : int
Return values
intgetOffset()
public
getOffset() : int
Return values
intgetOrderBy()
public
getOrderBy() : array<string|int, mixed>
Return values
array<string|int, mixed>getParamInfo()
Get documentation for one or all params
public
getParamInfo([string $param = null ]) : array<string|int, mixed>
Parameters
- $param : string = null
Return values
array<string|int, mixed> —of arrays [description, type, default, (comment)]
getParams()
Serialize this object's params into an array
public
getParams() : array<string|int, mixed>
Return values
array<string|int, mixed>getPermissions()
public
getPermissions() : array<string|int, mixed>
Return values
array<string|int, mixed>getWhere()
public
getWhere() : array<string|int, mixed>
Return values
array<string|int, mixed>offsetExists()
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Tags
Return values
booloffsetGet()
public
& offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
Tags
Attributes
- #[ReturnTypeWillChange]
offsetSet()
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
Tags
offsetUnset()
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
Tags
paramExists()
public
paramExists(string $param) : bool
Parameters
- $param : string
Return values
boolreflect()
public
reflect() : ReflectionClass
Return values
ReflectionClasssetChain()
public
setChain(array<string|int, mixed> $chain) : $this
Parameters
- $chain : array<string|int, mixed>
Return values
$thissetCheckPermissions()
public
setCheckPermissions(bool $checkPermissions) : $this
Parameters
- $checkPermissions : bool
Return values
$thissetDebug()
public
setDebug(bool $debug) : $this
Enable/disable debug output
Parameters
- $debug : bool
Return values
$thissetLanguage()
public
setLanguage(string|null $language) : $this
Parameters
- $language : string|null
Return values
$thissetLimit()
public
setLimit(int $limit) : $this
Parameters
- $limit : int
Return values
$thissetOffset()
public
setOffset(int $offset) : $this
Parameters
- $offset : int
Return values
$thissetOrderBy()
public
setOrderBy(array<string|int, mixed> $order) : $this
Parameters
- $order : array<string|int, mixed>
Return values
$thissetVersion()
public
setVersion(int $val) : $this
Parameters
- $val : int
Tags
Return values
$thissetWhere()
public
setWhere(array<string|int, mixed> $wheres) : $this
Parameters
- $wheres : array<string|int, mixed>
Return values
$thisaddCallbackToDebugOutput()
When in debug mode, this logs the callback function being used by a Basic*Action class.
protected
addCallbackToDebugOutput(callable $callable) : mixed
Parameters
- $callable : callable
checkRequiredFields()
Validates required fields for actions which create a new object.
protected
checkRequiredFields(mixed $values) : array<string|int, mixed>
Parameters
- $values : mixed
Tags
Return values
array<string|int, mixed>doTask()
This Basic Batch class can be used in one of two ways:
protected
doTask(mixed $item) : array<string|int, mixed>
- Use this class directly by passing a callable ($doer) to the constructor.
- Extend this class and override this function.
Either way, this function should return an array with an output record for the item.
Parameters
- $item : mixed
Return values
array<string|int, mixed>formatWriteValues()
Replaces pseudoconstants in input values
protected
formatWriteValues(array<string|int, mixed> &$record) : mixed
Parameters
- $record : array<string|int, mixed>
Tags
getBatchAction()
Get an API action object which resolves the list of records for this batch.
protected
getBatchAction() : AbstractGetAction
This is similar to getBatchRecords(), but you may further refine the
API call (e.g. selecting different fields or data-pages) before executing.
Return values
AbstractGetActiongetBatchRecords()
Get a list of records for this batch.
protected
getBatchRecords() : array<string|int, mixed>
Return values
array<string|int, mixed>getLanguageOptions()
Get available preferred languages.
protected
getLanguageOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getMagicProperties()
Get a list of class properties for which magic methods are supported.
protected
static getMagicProperties() : array<string|int, mixed>
Return values
array<string|int, mixed> —List of supported properties, keyed by property name. Array(string $propertyName => bool $true).
getParamDefaults()
protected
getParamDefaults() : array<string|int, mixed>
Return values
array<string|int, mixed>getSelect()
Determines what fields will be returned by getBatchRecords
protected
getSelect() : array<string|int, string>
Defaults to an entity's primary key(s), typically ['id']
Return values
array<string|int, string>parseGroupNameFromFormName()
For afform base name, get the custom group name it corresponds to Or null if none
protected
static parseGroupNameFromFormName(string $name) : string|null
Parameters
- $name : string
Return values
string|nullparseGroupNamesFromAfformGetNames()
protected
static parseGroupNamesFromAfformGetNames(array<string|int, mixed> $getNames) : array<string|int, mixed>
Parameters
- $getNames : array<string|int, mixed>
Return values
array<string|int, mixed>processBatch()
Calls doTask once per item and stores the result.
protected
processBatch(Result $result, array<string|int, mixed> $items) : mixed
We pass the doTask function an array representing one item to process. We expect to get the same format back.
Note: This function may be overridden by the end api.
Parameters
- $result : Result
- $items : array<string|int, mixed>
Tags
reloadResults()
protected
reloadResults(array<string|int, mixed> $savedRecords[, array<string|int, mixed>|bool $select = true ]) : array<string|int, mixed>
Parameters
- $savedRecords : array<string|int, mixed>
- $select : array<string|int, mixed>|bool = true
Tags
Return values
array<string|int, mixed>whereClauseToString()
Produces a human-readable where clause, for the reading enjoyment of you humans.
protected
whereClauseToString([array<string|int, mixed> $whereClause = null ][, string $op = 'AND' ]) : string
Parameters
- $whereClause : array<string|int, mixed> = null
- $op : string = 'AND'
Return values
stringgenerateCreateForm()
private
generateCreateForm(mixed $item) : array<string|int, mixed>
Parameters
- $item : mixed
Return values
array<string|int, mixed>generateFieldBlock()
private
generateFieldBlock(mixed $item) : array<string|int, mixed>
Parameters
- $item : mixed
Return values
array<string|int, mixed>generateTabForm()
private
generateTabForm(mixed $item) : array<string|int, mixed>
Parameters
- $item : mixed
Return values
array<string|int, mixed>generateUpdateForm()
private
generateUpdateForm(mixed $item) : array<string|int, mixed>
Parameters
- $item : mixed
Return values
array<string|int, mixed>generateViewForm()
private
generateViewForm(mixed $item) : array<string|int, mixed>
Parameters
- $item : mixed