CRM_Contact_Form_ContactFormTrait uses trait:short
Trait implements getContactValue + overridable getContactID functions.
These are commonly used on forms - although getContactID() would often
be overridden. By using these functions it is not necessary to know
if the Contact ID has already been defined as getContactID() will retrieve
them form the values available (unless it is yet to be created).
Table of Contents
Properties
- $entityLookupDefinitions : array<string|int, mixed>
- Array of defined entity identifiers.
- $entityLookupValues : array<string|int, mixed>
- Array of defined entity values.
Methods
- getContactID() : int|null
- Get the contact ID.
- getContactValue() : mixed
- Get a value for the contact being acted on in the form.
- isDefined() : bool
- Check if an entity can be looked up
- lookup() : mixed
- Retrieve a field value for a defined entity
- define() : void
- Defines a record so its values can be retrieved using `$this->lookup()`
- getDefinition() : array{entityName: string, identifier: array}|null
- Retrieve entity definition (entityName string, identifier [keys/values])
Properties
$entityLookupDefinitions
Array of defined entity identifiers.
private
array<string|int, mixed>
$entityLookupDefinitions
= []
$entityLookupValues
Array of defined entity values.
private
array<string|int, mixed>
$entityLookupValues
= []
Methods
getContactID()
Get the contact ID.
public
getContactID() : int|null
Override this for more complex retrieval as required by the form.
Tags
Return values
int|nullgetContactValue()
Get a value for the contact being acted on in the form.
public
getContactValue(mixed $fieldName) : mixed
This can be called from any point in the form flow and if the contact can not yet be determined it will return NULL.
Parameters
- $fieldName : mixed
Tags
isDefined()
Check if an entity can be looked up
public
isDefined(string $nickname) : bool
Parameters
- $nickname : string
Return values
boollookup()
Retrieve a field value for a defined entity
public
lookup(string $nickname, string $fieldName) : mixed
Parameters
- $nickname : string
-
Handle set by
$this->define() - $fieldName : string
Tags
define()
Defines a record so its values can be retrieved using `$this->lookup()`
protected
define(string $apiEntityName, string $nickname, array<string|int, mixed> $identifier) : void
Parameters
- $apiEntityName : string
- $nickname : string
-
Handle to use to retrieve values with
$this->lookup() - $identifier : array<string|int, mixed>
-
A unique key or combination of keys to uniquely identify the record (usually id) Most commonly looks like
['id' => 123]
getDefinition()
Retrieve entity definition (entityName string, identifier [keys/values])
protected
getDefinition(string $nickname) : array{entityName: string, identifier: array}|null
Parameters
- $nickname : string