Documentation

SubmitFile extends AbstractProcessor
in package

Special-purpose API for uploading files as part of a form submission.

This API is meant to be called with a multipart POST ajax request which includes the uploaded file.

Table of Contents

Properties

$_debugOutput  : mixed
$_actionName  : string
$_afform  : array<string|int, mixed>
$_entityIds  : array<string|int, mixed>
Ids of each autoloaded entity.
$_entityName  : string
$_entityValues  : mixed
$_formDataModel  : FormDataModel
$args  : array<string|int, mixed>
Arguments present when loading the form
$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.
$entityIndex  : string|int
$fieldName  : string
$fillMode  : string
Mode indicates what is being prefilled.
$joinEntity  : string
$joinIndex  : string|int
$language  : string
Preferred language (optional)
$modelName  : string
$name  : string
Form name
$token  : string
Submission token
$version  : int
Api version number; cannot be changed.
$_arrayStorage  : array<string|int, mixed>
$_entityFields  : array<string|int, mixed>
$_id  : int
$_paramInfo  : array<string|int, mixed>
$_reflection  : ReflectionClass

Methods

__call()  : static|mixed
Magic function to provide automatic getter/setter for params.
__construct()  : mixed
Action constructor.
__set()  : mixed
Strictly enforce api parameters
_run()  : mixed
addChain()  : $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
getArgs()  : array<string|int, mixed>
getChain()  : array<string|int, mixed>
getCheckPermissions()  : bool
getDebug()  : bool
getEntityField()  : array<string|int, mixed>|null
Get field definition for a given entity
getEntityFields()  : array<string|int, mixed>
Get all fields for a given entity
getEntityIndex()  : int
getEntityName()  : string
getFieldName()  : string
getFillMode()  : string
getJoinEntity()  : string
getJoinIndex()  : int
getJoinResult()  : array<string|int, mixed>
getLanguage()  : string|null
getModelName()  : string
getName()  : string
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>
getToken()  : string
loadEntity()  : void
Fetch all data needed to display a given entity on this form
loadJoins()  : array<string|int, mixed>
Finds all joins after loading an entity.
offsetExists()  : bool
offsetGet()  : mixed
offsetSet()  : void
offsetUnset()  : void
paramExists()  : bool
preprocessSubmittedValues()  : mixed
Preprocess submitted values
processFormData()  : mixed
Process form data
reflect()  : ReflectionClass
setArgs()  : $this
setChain()  : $this
setCheckPermissions()  : $this
setDebug()  : $this
setEntityIndex()  : $this
setFieldName()  : $this
setFillMode()  : $this
setJoinEntity()  : $this
setJoinIndex()  : $this
setLanguage()  : $this
setModelName()  : $this
setName()  : $this
setToken()  : $this
setVersion()  : $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.
combineValuesAndIds()  : mixed
Recursively add entity IDs to the values.
fillIdFields()  : void
formatWriteValues()  : mixed
Replaces pseudoconstants in input values
getFileFields()  : array<string|int, mixed>
getFkField()  : array<string|int, mixed>|null
getJoinWhereClause()  : array<string|int, array<string|int, mixed>>
Gets the clause for looking up join entities, or NULL if not available.
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.
getNestedKey()  : int|string|null
Given a nested array like `[0 => ['id' => 123]]`, this returns the first key from the inner array, e.g. `'id'`.
getParamDefaults()  : array<string|int, mixed>
getSubmittableFields()  : array<string|int, mixed>
loadEntities()  : mixed
Load entityIds from web token
prePopulateSubmissionData()  : mixed
Load the data from submission table
processForm()  : array<string|int, mixed>
replaceReferences()  : mixed
Replace Entity reference fields with the id of the referenced entity.
apiGet()  : array<string|int, mixed>
Delegated by loadEntity to call API.get and fill in additioal info
loadJoin()  : array<string|int, mixed>
Directly loads a join entity e.g. from an autocomplete field in the join block.
validateBySavedSearch()  : array<string|int, mixed>
Validate that given id(s) are actually returned by the Autocomplete API

Properties

$_entityIds

Ids of each autoloaded entity.

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

Each key in the array corresponds to the name of an entity, and the value is an array of arrays (because of <af-repeat> all entities are treated as if they may be multi) E.g. $entityIds['Individual1'] = [['id' => 1, 'joins' => ['Email' => [['id' => 1], ['id' => 2]]];

$args

Arguments present when loading the form

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

$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.

$fieldName

protected string $fieldName
Tags
required

$fillMode

Mode indicates what is being prefilled.

protected string $fillMode = 'form'

Either the entire form, or a specific entity, or a join for an entity.

Tags
options

form,entity,join

$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
optionsCallback

getLanguageOptions

$modelName

protected string $modelName
Tags
required

$token

Submission token

protected string $token
Tags
required

$version

Api version number; cannot be changed.

protected int $version = 4

$_arrayStorage

private array<string|int, mixed> $_arrayStorage = []

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
throws
CRM_Core_Exception
Return values
static|mixed

__construct()

Action constructor.

public __construct(string $entityName, string $actionName) : mixed
Parameters
$entityName : string
$actionName : string

__set()

Strictly enforce api parameters

public __set(mixed $name, mixed $value) : mixed
Parameters
$name : mixed
$value : mixed
Tags
throws
Exception

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 $index param

Return values
$this

entityFields()

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
see
GetFields
throws
CRM_Core_Exception
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
throws
CRM_Core_Exception
throws
Exception
Return values
bool

getActionName()

public getActionName() : string
Return values
string

getArgs()

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

getChain()

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

getCheckPermissions()

public getCheckPermissions() : bool
Return values
bool

getEntityField()

Get field definition for a given entity

public static getEntityField(string $entityName, string $fieldName) : array<string|int, mixed>|null
Parameters
$entityName : string
$fieldName : string
Tags
throws
CRM_Core_Exception
Return values
array<string|int, mixed>|null

getEntityFields()

Get all fields for a given entity

public static getEntityFields(string $entityName) : array<string|int, mixed>
Parameters
$entityName : string
Tags
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

getEntityIndex()

public getEntityIndex() : int
Return values
int

getEntityName()

public getEntityName() : string
Return values
string

getFieldName()

public getFieldName() : string
Return values
string

getJoinEntity()

public getJoinEntity() : string
Return values
string

getJoinIndex()

public getJoinIndex() : int
Return values
int

getJoinResult()

public getJoinResult(array<string|int, mixed> $afEntity, string $joinEntity, array<string|int, mixed> $join, array<string|int, mixed> $where, int $limit) : array<string|int, mixed>
Parameters
$afEntity : array<string|int, mixed>
$joinEntity : string
$join : array<string|int, mixed>
$where : array<string|int, mixed>
$limit : int
Return values
array<string|int, mixed>

getLanguage()

public getLanguage() : string|null
Return values
string|null

getModelName()

public getModelName() : string
Return values
string

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>

getToken()

public getToken() : string
Return values
string

loadEntity()

Fetch all data needed to display a given entity on this form

public loadEntity(array<string|int, mixed> $entity, array<string|int, array<string|int, mixed>> $values[, string $mode = 'update' ]) : void
Parameters
$entity : array<string|int, mixed>

Afform entity definition

$values : array<string|int, array<string|int, mixed>>

Array of value arrays. Each must be the primary key, e.g.

[
  ['id' => 123],
  ['id' => 456],
]

In theory we could include other stuff in the values, but it's not currently supported.

$mode : string = 'update'

'update' or 'create' ('create' is only used in special cases like Event.template_id)

loadJoins()

Finds all joins after loading an entity.

public loadJoins(mixed $joinEntity, mixed $join, mixed $afEntity, mixed $entityId, mixed $index) : array<string|int, mixed>
Parameters
$joinEntity : mixed
$join : mixed
$afEntity : mixed
$entityId : mixed
$index : mixed
Return values
array<string|int, mixed>

offsetExists()

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
Tags
inheritDoc
Return values
bool

offsetGet()

public & offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed
Tags
inheritDoc
Attributes
#[ReturnTypeWillChange]

offsetSet()

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed
Tags
inheritDoc

offsetUnset()

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed
Tags
inheritDoc

paramExists()

public paramExists(string $param) : bool
Parameters
$param : string
Return values
bool

preprocessSubmittedValues()

Preprocess submitted values

public preprocessSubmittedValues(array<string|int, mixed> $submittedValues) : mixed
Parameters
$submittedValues : array<string|int, mixed>

processFormData()

Process form data

public processFormData(array<string|int, mixed> $entityValues) : mixed
Parameters
$entityValues : array<string|int, mixed>

reflect()

public reflect() : ReflectionClass
Return values
ReflectionClass

setArgs()

public setArgs(array<string|int, mixed> $args) : $this
Parameters
$args : array<string|int, mixed>
Return values
$this

setChain()

public setChain([array<string|int, mixed> $chain = ]) : $this
Parameters
$chain : array<string|int, mixed> =
Return values
$this

setCheckPermissions()

public setCheckPermissions(bool $checkPermissions) : $this
Parameters
$checkPermissions : bool
Return values
$this

setDebug()

public setDebug([bool $debug = ]) : $this

Enable/disable debug output

Parameters
$debug : bool =
Return values
$this

setEntityIndex()

public setEntityIndex([int $entityIndex = ]) : $this
Parameters
$entityIndex : int =
Return values
$this

setFieldName()

public setFieldName([string $fieldName = ]) : $this
Parameters
$fieldName : string =
Return values
$this

setFillMode()

public setFillMode([string $fillMode = ]) : $this

Set entity/form fill mode.

Parameters
$fillMode : string =
Return values
$this

setJoinEntity()

public setJoinEntity([string $joinEntity = ]) : $this
Parameters
$joinEntity : string =
Return values
$this

setJoinIndex()

public setJoinIndex([int $joinIndex = ]) : $this
Parameters
$joinIndex : int =
Return values
$this

setLanguage()

public setLanguage([string|null $language = ]) : $this
Parameters
$language : string|null =
Return values
$this

setModelName()

public setModelName([string $modelName = ]) : $this
Parameters
$modelName : string =
Return values
$this

setName()

public setName(string $name) : $this
Parameters
$name : string
Return values
$this

setToken()

public setToken([string $token = ]) : $this
Parameters
$token : string =
Return values
$this

addCallbackToDebugOutput()

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
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

combineValuesAndIds()

Recursively add entity IDs to the values.

protected combineValuesAndIds(mixed $values, mixed $ids[, mixed $isJoin = FALSE ]) : mixed
Parameters
$values : mixed
$ids : mixed
$isJoin : mixed = FALSE

fillIdFields()

protected fillIdFields(array<string|int, mixed> &$records, string $entityName) : void
Parameters
$records : array<string|int, mixed>
$entityName : string

formatWriteValues()

Replaces pseudoconstants in input values

protected formatWriteValues(array<string|int, mixed> &$record) : mixed
Parameters
$record : array<string|int, mixed>
Tags
throws
CRM_Core_Exception

getFileFields()

protected static getFileFields(mixed $entityName, mixed $entityFields) : array<string|int, mixed>
Parameters
$entityName : mixed
$entityFields : mixed
Return values
array<string|int, mixed>

getFkField()

protected static getFkField(mixed $mainEntity, mixed $otherEntity) : array<string|int, mixed>|null
Parameters
$mainEntity : mixed
$otherEntity : mixed
Return values
array<string|int, mixed>|null

getJoinWhereClause()

Gets the clause for looking up join entities, or NULL if not available.

protected static getJoinWhereClause(FormDataModel $formDataModel, string $mainEntityName, string $joinEntityType, int|string $mainEntityId) : array<string|int, array<string|int, mixed>>

Joins can come in two styles:

  • Forward FK e.g. Event.loc_block_id => LocBlock
  • Reverse FK e.g. Contact <= Email.contact_id
Parameters
$formDataModel : FormDataModel
$mainEntityName : string
$joinEntityType : string
$mainEntityId : int|string
Tags
throws
CRM_Core_Exception
Return values
array<string|int, 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).

getNestedKey()

Given a nested array like `[0 => ['id' => 123]]`, this returns the first key from the inner array, e.g. `'id'`.

protected static getNestedKey(array<string|int, mixed> $values) : int|string|null
Parameters
$values : array<string|int, mixed>
Return values
int|string|null

getParamDefaults()

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

getSubmittableFields()

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

loadEntities()

Load entityIds from web token

protected loadEntities() : mixed

prePopulateSubmissionData()

Load the data from submission table

protected prePopulateSubmissionData() : mixed

processForm()

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

replaceReferences()

Replace Entity reference fields with the id of the referenced entity.

protected replaceReferences(string $entityName, mixed $records) : mixed
Parameters
$entityName : string
$records : mixed

apiGet()

Delegated by loadEntity to call API.get and fill in additioal info

private apiGet(string $afEntityName, string $apiEntityName, array<string|int, mixed> $entityFields, string $keyField, array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
$afEntityName : string

e.g. Individual1

$apiEntityName : string

Not necessarily the api of the afEntity, in the case of joins it will be different.

$entityFields : array<string|int, mixed>
$keyField : string
$params : array<string|int, mixed>
Return values
array<string|int, mixed>

loadJoin()

Directly loads a join entity e.g. from an autocomplete field in the join block.

private loadJoin(array<string|int, mixed> $afEntity, array<string|int, mixed> $values) : array<string|int, mixed>
Parameters
$afEntity : array<string|int, mixed>
$values : array<string|int, mixed>
Return values
array<string|int, mixed>

validateBySavedSearch()

Validate that given id(s) are actually returned by the Autocomplete API

private validateBySavedSearch(string $afEntityName, string $apiEntity, array<string|int, mixed> $ids, string $matchField) : array<string|int, mixed>
Parameters
$afEntityName : string
$apiEntity : string
$ids : array<string|int, mixed>
$matchField : string
Tags
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

        
On this page

Search results