CRM_Core_Form_EntityFormTrait
Tags
Table of Contents
Properties
- $_id : int
- The id of the object being edited / created.
- $_entitySubTypeId : int
- The entity subtype ID (eg. for Relationship / Activity)
- $deleteMessage : string
- Deletion message to be assigned to the form.
- $entityFields : array<string|int, mixed>
- Fields for the entity to be assigned to the template.
- $metadata : array<string|int, mixed>
- Metadata from getfields API call for the current entity.
Methods
- addCustomDataToForm() : mixed
- If the custom data is in the submitted data (eg. added via ajax loaded form) add to form.
- buildQuickEntityForm() : mixed
- Build the form object.
- getDefaultContext() : mixed
- Explicitly declare the form context.
- getDeleteMessage() : string
- Get entity fields for the entity to be added to the form.
- getEntityFields() : array<string|int, mixed>
- Get entity fields for the entity to be added to the form.
- getEntityId() : int|null
- Get the entity id being edited.
- getEntitySubTypeId() : int|null
- Get the entity subtype ID being edited
- setDeleteMessage() : mixed
- Set the delete message.
- setEntityId() : mixed
- Set the entity ID
- setEntitySubTypeId() : mixed
- Set the entity subtype ID being edited
- addEntityFieldsToTemplate() : mixed
- Add defined entity field to template.
- addFormButtons() : mixed
- Add relevant buttons to the form.
- buildDeleteForm() : mixed
- Build the form for any deletion.
- getEntityDefaults() : mixed
- Get the defaults for the entity.
- getValidationTypeForField() : string|int|bool
- Get the validation rule to apply to a function.
- isDeleteContext() : bool
- Is the form being used in the context of a deletion.
- isSuppressCustomData() : bool
- Should custom data be suppressed on this form.
- isViewContext() : bool
- Is the form being used in the context of a view.
- setEntityFields() : mixed
- Set entity fields to be assigned to the form.
- setEntityFieldsMetadata() : mixed
- setTranslatedFields() : mixed
- Set translated fields.
Properties
$_id
The id of the object being edited / created.
public
int
$_id
$_entitySubTypeId
The entity subtype ID (eg. for Relationship / Activity)
protected
int
$_entitySubTypeId
= \NULL
$deleteMessage
Deletion message to be assigned to the form.
protected
string
$deleteMessage
Depending on the screen, the deletionMessage may be plain-text ({$deletionMessage|escape}
)
or HTML ({$deletionMessage nofilter}
). Be sure your controller+template agree.
$entityFields
Fields for the entity to be assigned to the template.
protected
array<string|int, mixed>
$entityFields
= []
Fields may have keys
- name (required to show in tpl from the array)
- description (optional, will appear below the field)
- not-auto-addable - this class will not attempt to add the field using addField. (this will be automatically set if the field does not have html in it's metadata or is not a core field on the form's entity).
- help (option) add help to the field - e.g ['id' => 'id-source', 'file' => 'CRM/Contact/Form/Contact']]
- template - use a field specific template to render this field
- required
- is_freeze (field should be frozen).
$metadata
Metadata from getfields API call for the current entity.
protected
array<string|int, mixed>
$metadata
= []
Methods
addCustomDataToForm()
If the custom data is in the submitted data (eg. added via ajax loaded form) add to form.
public
addCustomDataToForm() : mixed
buildQuickEntityForm()
Build the form object.
public
buildQuickEntityForm() : mixed
getDefaultContext()
Explicitly declare the form context.
public
getDefaultContext() : mixed
getDeleteMessage()
Get entity fields for the entity to be added to the form.
public
getDeleteMessage() : string
Return values
stringgetEntityFields()
Get entity fields for the entity to be added to the form.
public
getEntityFields() : array<string|int, mixed>
Return values
array<string|int, mixed>getEntityId()
Get the entity id being edited.
public
getEntityId() : int|null
Return values
int|nullgetEntitySubTypeId()
Get the entity subtype ID being edited
public
getEntitySubTypeId() : int|null
Return values
int|nullsetDeleteMessage()
Set the delete message.
public
setDeleteMessage() : mixed
We do this from the constructor in order to do a translation.
setEntityId()
Set the entity ID
public
setEntityId(int $id) : mixed
Parameters
- $id : int
-
The entity ID
setEntitySubTypeId()
Set the entity subtype ID being edited
public
setEntitySubTypeId(mixed $subTypeId) : mixed
Parameters
- $subTypeId : mixed
addEntityFieldsToTemplate()
Add defined entity field to template.
protected
addEntityFieldsToTemplate() : mixed
addFormButtons()
Add relevant buttons to the form.
protected
addFormButtons() : mixed
buildDeleteForm()
Build the form for any deletion.
protected
buildDeleteForm() : mixed
getEntityDefaults()
Get the defaults for the entity.
protected
getEntityDefaults() : mixed
getValidationTypeForField()
Get the validation rule to apply to a function.
protected
getValidationTypeForField(string $fieldName) : string|int|bool
Alphanumeric is designed to always be safe & for now we just return that but in future we can use tighter rules for types like int, bool etc.
Parameters
- $fieldName : string
Return values
string|int|boolisDeleteContext()
Is the form being used in the context of a deletion.
protected
isDeleteContext() : bool
(For some reason rather than having separate forms Civi overloads one form).
Return values
boolisSuppressCustomData()
Should custom data be suppressed on this form.
protected
isSuppressCustomData() : bool
Return values
boolisViewContext()
Is the form being used in the context of a view.
protected
isViewContext() : bool
Return values
boolsetEntityFields()
Set entity fields to be assigned to the form.
protected
setEntityFields() : mixed
setEntityFieldsMetadata()
protected
setEntityFieldsMetadata() : mixed
setTranslatedFields()
Set translated fields.
protected
setTranslatedFields() : mixed
This function is called from the class constructor, allowing us to set fields on the class that can't be set as properties due to need for translation or other non-input specific handling.