Documentation

CRM_Member_Tokens extends CRM_Core_EntityTokens
in package

Class CRM_Member_Tokens

Generate "member.*" tokens.

This TokenSubscriber was produced by refactoring the code from the scheduled-reminder system with the goal of making that system more flexible. The current implementation is still coupled to scheduled-reminders. It would be good to figure out a more generic implementation which is not tied to scheduled reminders, although that is outside the current scope.

Table of Contents

Properties

$activeTokens  : array<string|int, mixed>
$entity  : string
$tokenNames  : array<string|int, mixed>
$checkPermissions  : bool
Should permissions be checked when loading tokens.
$fieldMetadata  : array<string|int, mixed>
Metadata about the entity fields.
$prefetch  : array<string|int, mixed>
$tokensMetadata  : array<string|int, mixed>
Metadata about all tokens.

Methods

__construct()  : mixed
Class constructor.
alterActionScheduleQuery()  : void
Alter action schedule query.
checkActive()  : bool
Check if the token processor is active.
evaluateToken()  : mixed
Evaluate the content of a single token.
evaluateTokens()  : mixed
Populate the token data.
getActiveTokens()  : mixed
To handle variable tokens, override this function and return the active tokens.
getDependencies()  : array<string|int, mixed>
Get fields which need to be returned to render another token.
getExtendableTableName()  : string
Get the name of the table this token class can extend.
getPrefetchFields()  : array<string|int, mixed>
Get the fields required to prefetch the entity.
getSubscribedEvents()  : mixed
isHTMLTextField()  : bool
Is the text stored in html format.
prefetch()  : mixed
To perform a bulk lookup before rendering tokens, override this function and return the prefetched data.
registerTokens()  : mixed
Register the declared tokens.
addFieldToTokenMetadata()  : void
Add the token to the metadata based on the field spec.
getApiEntityName()  : string
Get the entity name for api v4 calls.
getBasicTokens()  : array<string|int, string>
getBespokeTokens()  : array<string|int, mixed>
Get any tokens with custom calculation.
getCacheKey()  : string
Get a cache key appropriate to the current usage.
getCurrency()  : string
Get the currency to use for formatting money.
getCurrencyFieldName()  : mixed
getCustomFieldName()  : string
Get the apiv4 style custom field name.
getCustomFieldValue()  : array<string|int, mixed>|string|void|null
getDeprecatedTokens()  : array<string|int, string>
These tokens still work but we don't advertise them.
getEntityAlias()  : string
Get the entity alias to use within queries.
getEntityIDField()  : string
getEntityName()  : string
getExposedFields()  : array<string|int, string>
List out the fields that are exposed.
getFieldMetadata()  : array<string|int, mixed>
Get the metadata for the available fields.
getFieldValue()  : string|int
getHiddenTokens()  : array<string|int, mixed>
Get tokens to be suppressed from the widget.
getMetadataForField()  : array<string|int, mixed>
Get the metadata for the field.
getRelatedTokens()  : array<string|int, mixed>
Get related tokens related to membership e.g. recurring contribution tokens
getRelatedTokensForEntity()  : array<string|int, mixed>
Get metadata for tokens for a related entity joined by a field on the main entity.
getReturnFields()  : array<string|int, string>
Get an array of fields to be requested.
getSkippedFields()  : array<string|int, string>
Get entity fields that should not be exposed as tokens.
getTokenMappingsForRelatedEntities()  : array<string|int, mixed>
Get token mappings for related entities - specifically the contact entity.
getTokenMetadata()  : array<string|int, mixed>
Get the metadata about the available tokens
getTokenMetadataOverrides()  : array<string|int, array<string|int, string>>
Get any overrides for token metadata.
isBooleanField()  : bool
Is the given field a boolean field.
isCustomField()  : bool
Is the given field a custom field.
isDateField()  : bool
Is the given field a date field.
isMoneyField()  : bool
Is the given field a date field.
isPseudoField()  : bool
Is the given field a pseudo field.

Properties

$activeTokens

public array<string|int, mixed> $activeTokens

List of active tokens - tokens provided by this class and used in the message Array(string $tokenName);

$tokenNames

public array<string|int, mixed> $tokenNames

List of tokens provided by this class Array(string $fieldName => string $label).

$checkPermissions

Should permissions be checked when loading tokens.

protected bool $checkPermissions = \FALSE

$fieldMetadata

Metadata about the entity fields.

protected array<string|int, mixed> $fieldMetadata = []

$prefetch

protected array<string|int, mixed> $prefetch = []

$tokensMetadata

Metadata about all tokens.

protected array<string|int, mixed> $tokensMetadata = []

Methods

__construct()

Class constructor.

public __construct() : mixed

evaluateToken()

Evaluate the content of a single token.

public evaluateToken(TokenRow $row, mixed $entity, mixed $field[, mixed $prefetch = NULL ]) : mixed
Parameters
$row : TokenRow

The record for which we want token values.

$entity : mixed

The name of the token entity.

$field : mixed

The name of the token field.

$prefetch : mixed = NULL

Any data that was returned by the prefetch().

Tags
inheritDoc
throws
CRM_Core_Exception

getDependencies()

Get fields which need to be returned to render another token.

public getDependencies() : array<string|int, mixed>
Return values
array<string|int, mixed>

getExtendableTableName()

Get the name of the table this token class can extend.

public getExtendableTableName() : string

The default is based on the entity but some token classes, specifically the event class, latch on to other tables - ie the participant table.

Return values
string

isHTMLTextField()

Is the text stored in html format.

public isHTMLTextField(string $fieldName) : bool
Parameters
$fieldName : string
Return values
bool

addFieldToTokenMetadata()

Add the token to the metadata based on the field spec.

protected addFieldToTokenMetadata(array<string|int, mixed> &$tokensMetadata, array<string|int, mixed> $field, array<string|int, mixed> $exposedFields[, string $prefix = '' ]) : void
Parameters
$tokensMetadata : array<string|int, mixed>
$field : array<string|int, mixed>
$exposedFields : array<string|int, mixed>
$prefix : string = ''

getApiEntityName()

Get the entity name for api v4 calls.

protected getApiEntityName() : string
Return values
string

getBasicTokens()

protected getBasicTokens() : array<string|int, string>
Tags
todo

remove this function & use the metadata that is loaded.

throws
CRM_Core_Exception
Return values
array<string|int, string>

getBespokeTokens()

Get any tokens with custom calculation.

protected getBespokeTokens() : array<string|int, mixed>

In this case 'fee' should be converted to{membership.membership_type_id.fee} but we don't have the formatting support to do that with no custom intervention yet.

Return values
array<string|int, mixed>

getCacheKey()

Get a cache key appropriate to the current usage.

protected getCacheKey() : string
Return values
string

getCurrency()

Get the currency to use for formatting money.

protected getCurrency(mixed $row) : string
Parameters
$row : mixed
Return values
string

getCurrencyFieldName()

protected getCurrencyFieldName() : mixed

getCustomFieldName()

Get the apiv4 style custom field name.

protected getCustomFieldName(int $id) : string
Parameters
$id : int
Tags
throws
CRM_Core_Exception
Return values
string

getCustomFieldValue()

protected getCustomFieldValue(mixed $entityID, string $field) : array<string|int, mixed>|string|void|null
Parameters
$entityID : mixed
$field : string

eg. 'custom_1'

Tags
throws
CRM_Core_Exception
Return values
array<string|int, mixed>|string|void|null

$mixed

getDeprecatedTokens()

These tokens still work but we don't advertise them.

protected getDeprecatedTokens() : array<string|int, string>

We will actively remove from the following places

  • scheduled reminders
  • add to 'blocked' on pdf letter & email

& then at some point start issuing warnings for them.

Return values
array<string|int, string>

getEntityAlias()

Get the entity alias to use within queries.

protected getEntityAlias() : string

The default has a double underscore which should prevent any ambiguity with an existing table name.

Return values
string

getEntityIDField()

protected getEntityIDField() : string
Return values
string

getEntityName()

protected getEntityName() : string
Return values
string

getExposedFields()

List out the fields that are exposed.

protected getExposedFields() : array<string|int, string>

For historical reasons these are the only exposed fields.

It is also possible to list 'skippedFields'

Return values
array<string|int, string>

getFieldMetadata()

Get the metadata for the available fields.

protected getFieldMetadata() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFieldValue()

protected getFieldValue(TokenRow $row, string $field) : string|int
Parameters
$row : TokenRow
$field : string
Return values
string|int

getHiddenTokens()

Get tokens to be suppressed from the widget.

protected getHiddenTokens() : array<string|int, mixed>

Note this is expected to be an interim function. Now we are no longer working around the parent function we can just define them once... with metadata, in a future refactor.

Return values
array<string|int, mixed>

getMetadataForField()

Get the metadata for the field.

protected getMetadataForField(string $fieldName) : array<string|int, mixed>
Parameters
$fieldName : string
Return values
array<string|int, mixed>

getRelatedTokens()

Get related tokens related to membership e.g. recurring contribution tokens

protected getRelatedTokens() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRelatedTokensForEntity()

Get metadata for tokens for a related entity joined by a field on the main entity.

protected getRelatedTokensForEntity(string $entity, string $joinField, array<string|int, mixed> $tokenList[, array<string|int, mixed> $hiddenTokens = [] ]) : array<string|int, mixed>
Parameters
$entity : string
$joinField : string
$tokenList : array<string|int, mixed>
$hiddenTokens : array<string|int, mixed> = []
Tags
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

getReturnFields()

Get an array of fields to be requested.

protected getReturnFields() : array<string|int, string>
Tags
todo

this function should look up tokenMetadata that is already loaded.

Return values
array<string|int, string>

getSkippedFields()

Get entity fields that should not be exposed as tokens.

protected getSkippedFields() : array<string|int, string>
Return values
array<string|int, string>

getTokenMappingsForRelatedEntities()

Get token mappings for related entities - specifically the contact entity.

protected getTokenMappingsForRelatedEntities() : array<string|int, mixed>

This function exists to help manage the way contact tokens is structured of an query-object style result set that needs to be mapped to apiv4.

The end goal is likely to be to advertised tokens that better map to api v4 and deprecate the existing ones but that is a long-term migration.

Return values
array<string|int, mixed>

getTokenMetadata()

Get the metadata about the available tokens

protected getTokenMetadata() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTokenMetadataOverrides()

Get any overrides for token metadata.

protected getTokenMetadataOverrides() : array<string|int, array<string|int, string>>

This is most obviously used for setting the audience, which will affect widget-presence.

Changing the audience is done in order to simplify the UI for more general users.

Return values
array<string|int, array<string|int, string>>

isBooleanField()

Is the given field a boolean field.

protected isBooleanField(string $fieldName) : bool
Parameters
$fieldName : string
Return values
bool

isCustomField()

Is the given field a custom field.

protected isCustomField(string $fieldName) : bool
Parameters
$fieldName : string
Return values
bool

isDateField()

Is the given field a date field.

protected isDateField(string $fieldName) : bool
Parameters
$fieldName : string
Return values
bool

isMoneyField()

Is the given field a date field.

protected isMoneyField(string $fieldName) : bool
Parameters
$fieldName : string
Return values
bool

isPseudoField()

Is the given field a pseudo field.

protected isPseudoField(string $fieldName) : bool
Parameters
$fieldName : string
Return values
bool

        
On this page

Search results