Form
extends Form
in package
implements
TranslatorAwareInterface
Uses
TranslatorAwareTrait
Configurable form.
Tags
Interfaces, Classes, Traits and Enums
- TranslatorAwareInterface
- Lightweight translator aware marker interface (used as an alternative to \Laminas\I18n\Translator\TranslatorAwareInterface, which requires an excessive number of methods to be implemented).
Table of Contents
- $defaultFormConfig : array<string|int, mixed>
- Default form configuration (from config.ini > Feedback)
- $formConfig : array<string|int, mixed>
- Form configuration
- $formElementConfig : array<string|int, mixed>
- Form element configuration
- $handlerManager : PluginManager
- Handler plugin manager
- $inputFilter : InputFilter
- Input filter
- $messages : array<string|int, mixed>
- Default, untranslated validation messages
- $translator : TranslatorInterface
- Translator
- $viewHelperManager : HelperPluginManager
- View helper manager.
- $vufindConfig : array<string|int, mixed>
- VuFind main configuration
- $yamlReader : YamlReader
- YAML reader
- __construct() : mixed
- Constructor
- formatEmailMessage() : array<string|int, mixed>
- Format email message.
- getDisplayString() : string
- Get display string.
- getEmailFromAddress() : string
- Return email from address
- getEmailFromName() : string
- Return email from name
- getEmailSubject() : string
- Return form email message subject.
- getFormElementConfig() : array<string|int, mixed>
- Return form element configuration.
- getFormId() : string
- Get current form id/name
- getHelp() : array<string|int, mixed>|null
- Return form help texts.
- getInputFilter() : InputFilterInterface
- Retrieve input filter used by this form
- getPrimaryHandler() : HandlerInterface
- Get primary form handler
- getRecipient() : array<string|int, mixed>
- Return form recipient(s).
- getSecondaryHandlers() : array<string|int, HandlerInterface>
- Get secondary form handlers
- getSubmitResponse() : string
- Return response that is shown after successful form submit.
- getTitle() : string
- Return form title.
- getTranslator() : TranslatorInterface
- Get translator object.
- getTranslatorLocale() : string
- Get the locale from the translator.
- isEnabled() : bool
- Check if form enabled.
- mapRequestParamsToFieldValues() : array<string|int, mixed>
- Map request parameters to field values
- reportReferrer() : bool
- Check if the form should report referrer url
- reportUserAgent() : bool
- Check if the form should report browser's user agent
- setFormId() : void
- Set form id
- setTranslator() : TranslatorAwareInterface
- Set a translator
- showOnlyForLoggedUsers() : bool
- Check if form is available only for logged users.
- translate() : string
- Translate a string (or string-castable object)
- translateWithPrefix() : string
- Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
- useCaptcha() : bool
- Check if the form should use Captcha validation (if supported)
- buildForm() : void
- Build form.
- extractTextDomain() : array<string|int, mixed>
- Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
- getDebugTranslation() : string
- Build a debug-mode translation
- getElementId() : string
- Get a complete id for an element
- getElementOptionGroups() : array<string|int, mixed>
- Get option groups for an element
- getElementOptions() : array<string|int, mixed>
- Get options for an element
- getFormConfig() : mixed
- Get form configuration
- getFormElement() : array<string|int, mixed>
- Get configuration for a Laminas form element
- getFormElementClass() : string|null
- Get form element class.
- getFormElements() : array<string|int, mixed>
- Get form elements
- getFormElementSettingFields() : array<string|int, mixed>
- Return a list of field names to read from form element settings.
- getFormSettingFields() : array<string|int, mixed>
- Return a list of field names to read from settings file.
- getProtectedFieldNames() : array<string|int, mixed>
- Return field names that should not be prefilled.
- getValidationMessage() : string
- Get translated validation message.
- mergeLocalConfig() : array<string|int, mixed>
- Merge local configuration into default configuration.
- parseConfig() : array<string|int, mixed>
- Parse form configuration.
- sanitizePrefill() : array<string|int, mixed>
- Validates prefill data and returns only the prefill values for enabled fields
- sanitizeTranslationKey() : string
- Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
- translateString() : string
- Get translation for a string
Properties
$defaultFormConfig
Default form configuration (from config.ini > Feedback)
protected
array<string|int, mixed>
$defaultFormConfig
$formConfig
Form configuration
protected
array<string|int, mixed>
$formConfig
$formElementConfig
Form element configuration
protected
array<string|int, mixed>
$formElementConfig
= []
$handlerManager
Handler plugin manager
protected
PluginManager
$handlerManager
$inputFilter
Input filter
protected
InputFilter
$inputFilter
$messages
Default, untranslated validation messages
protected
array<string|int, mixed>
$messages
= ['empty' => 'This field is required', 'invalid_email' => 'Email address is invalid']
$translator
Translator
protected
TranslatorInterface
$translator
= null
$viewHelperManager
View helper manager.
protected
HelperPluginManager
$viewHelperManager
$vufindConfig
VuFind main configuration
protected
array<string|int, mixed>
$vufindConfig
$yamlReader
YAML reader
protected
YamlReader
$yamlReader
Methods
__construct()
Constructor
public
__construct(YamlReader $yamlReader, HelperPluginManager $viewHelperManager, PluginManager $handlerManager[, array<string|int, mixed> $config = null ]) : mixed
Parameters
- $yamlReader : YamlReader
-
YAML reader
- $viewHelperManager : HelperPluginManager
-
View helper manager
- $handlerManager : PluginManager
-
Handler plugin manager
- $config : array<string|int, mixed> = null
-
VuFind main configuration (optional)
Tags
Return values
mixed —formatEmailMessage()
Format email message.
public
formatEmailMessage([array<string|int, mixed> $requestParams = [] ]) : array<string|int, mixed>
Parameters
- $requestParams : array<string|int, mixed> = []
-
Request parameters
Tags
Return values
array<string|int, mixed> —Array with template parameters and template name.
getDisplayString()
Get display string.
public
getDisplayString(string $translationKey[, bool $escape = null ]) : string
Parameters
- $translationKey : string
-
Translation key
- $escape : bool = null
-
Whether to escape the output. Default behaviour is to escape when the translation key does not end with '_html'.
Return values
string —getEmailFromAddress()
Return email from address
public
getEmailFromAddress() : string
Return values
string —getEmailFromName()
Return email from name
public
getEmailFromName() : string
Return values
string —getEmailSubject()
Return form email message subject.
public
getEmailSubject(array<string|int, mixed> $postParams) : string
Replaces any placeholders for form field values or labels with the submitted values.
Parameters
- $postParams : array<string|int, mixed>
-
Posted form data
Return values
string —getFormElementConfig()
Return form element configuration.
public
getFormElementConfig() : array<string|int, mixed>
Return values
array<string|int, mixed> —getFormId()
Get current form id/name
public
getFormId() : string
Return values
string —getHelp()
Return form help texts.
public
getHelp() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —getInputFilter()
Retrieve input filter used by this form
public
getInputFilter() : InputFilterInterface
Return values
InputFilterInterface —getPrimaryHandler()
Get primary form handler
public
getPrimaryHandler() : HandlerInterface
Return values
HandlerInterface —getRecipient()
Return form recipient(s).
public
getRecipient([array<string|int, mixed> $postParams = null ]) : array<string|int, mixed>
Parameters
- $postParams : array<string|int, mixed> = null
-
Posted form data
Tags
Return values
array<string|int, mixed> —of recipients, each consisting of an array with name, email or null if not configured
getSecondaryHandlers()
Get secondary form handlers
public
getSecondaryHandlers() : array<string|int, HandlerInterface>
Return values
array<string|int, HandlerInterface> —getSubmitResponse()
Return response that is shown after successful form submit.
public
getSubmitResponse() : string
Return values
string —getTitle()
Return form title.
public
getTitle() : string
Return values
string —getTranslator()
Get translator object.
public
getTranslator() : TranslatorInterface
Return values
TranslatorInterface —getTranslatorLocale()
Get the locale from the translator.
public
getTranslatorLocale([string $default = 'en' ]) : string
Parameters
- $default : string = 'en'
-
Default to use if translator absent.
Return values
string —isEnabled()
Check if form enabled.
public
isEnabled() : bool
Return values
bool —mapRequestParamsToFieldValues()
Map request parameters to field values
public
mapRequestParamsToFieldValues(array<string|int, mixed> $requestParams) : array<string|int, mixed>
Parameters
- $requestParams : array<string|int, mixed>
-
Request parameters
Return values
array<string|int, mixed> —reportReferrer()
Check if the form should report referrer url
public
reportReferrer() : bool
Return values
bool —reportUserAgent()
Check if the form should report browser's user agent
public
reportUserAgent() : bool
Return values
bool —setFormId()
Set form id
public
setFormId(string $formId[, array<string|int, mixed> $params = [] ][, array<string|int, mixed> $prefill = [] ]) : void
Parameters
- $formId : string
-
Form id
- $params : array<string|int, mixed> = []
-
Additional form parameters.
- $prefill : array<string|int, mixed> = []
-
Prefill form with these values.
Tags
Return values
void —setTranslator()
Set a translator
public
setTranslator(TranslatorInterface $translator) : TranslatorAwareInterface
Parameters
- $translator : TranslatorInterface
-
Translator
Return values
TranslatorAwareInterface —showOnlyForLoggedUsers()
Check if form is available only for logged users.
public
showOnlyForLoggedUsers() : bool
Return values
bool —translate()
Translate a string (or string-castable object)
public
translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —translateWithPrefix()
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
public
translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $prefix : string
-
Translation key prefix
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —useCaptcha()
Check if the form should use Captcha validation (if supported)
public
useCaptcha() : bool
Return values
bool —buildForm()
Build form.
protected
buildForm() : void
Return values
void —extractTextDomain()
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
protected
extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
Return values
array<string|int, mixed> —getDebugTranslation()
Build a debug-mode translation
protected
getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
- $domain : string
-
Text domain
- $str : string
-
String to translate
- $tokens : array<string|int, mixed>
-
Tokens to inject into the translated string
Return values
string —getElementId()
Get a complete id for an element
protected
getElementId(string $id) : string
Parameters
- $id : string
-
Element ID
Return values
string —getElementOptionGroups()
Get option groups for an element
protected
getElementOptionGroups(array<string|int, mixed> $element) : array<string|int, mixed>
Parameters
- $element : array<string|int, mixed>
-
Element configuration
Return values
array<string|int, mixed> —getElementOptions()
Get options for an element
protected
getElementOptions(array<string|int, mixed> $element) : array<string|int, mixed>
Parameters
- $element : array<string|int, mixed>
-
Element configuration
Return values
array<string|int, mixed> —getFormConfig()
Get form configuration
protected
getFormConfig([string $formId = null ]) : mixed
Parameters
- $formId : string = null
-
Form id
Tags
Return values
mixed —null|array
getFormElement()
Get configuration for a Laminas form element
protected
getFormElement(array<string|int, mixed> $el) : array<string|int, mixed>
Parameters
- $el : array<string|int, mixed>
-
Element configuration
Return values
array<string|int, mixed> —getFormElementClass()
Get form element class.
protected
getFormElementClass(string $type) : string|null
Parameters
- $type : string
-
Element type
Return values
string|null —getFormElements()
Get form elements
protected
getFormElements(array<string|int, mixed> $config) : array<string|int, mixed>
Parameters
- $config : array<string|int, mixed>
-
Form configuration
Return values
array<string|int, mixed> —getFormElementSettingFields()
Return a list of field names to read from form element settings.
protected
getFormElementSettingFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —getFormSettingFields()
Return a list of field names to read from settings file.
protected
getFormSettingFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —getProtectedFieldNames()
Return field names that should not be prefilled.
protected
getProtectedFieldNames() : array<string|int, mixed>
Return values
array<string|int, mixed> —getValidationMessage()
Get translated validation message.
protected
getValidationMessage(string $messageId) : string
Parameters
- $messageId : string
-
Message identifier
Return values
string —mergeLocalConfig()
Merge local configuration into default configuration.
protected
mergeLocalConfig(array<string|int, mixed> $config[, array<string|int, mixed>|null $localConfig = null ]) : array<string|int, mixed>
Parameters
- $config : array<string|int, mixed>
-
Default configuration
- $localConfig : array<string|int, mixed>|null = null
-
Local configuration
Return values
array<string|int, mixed> —parseConfig()
Parse form configuration.
protected
parseConfig(string $formId, array<string|int, mixed> $config, array<string|int, mixed> $params, array<string|int, mixed> $prefill) : array<string|int, mixed>
Parameters
- $formId : string
-
Form id
- $config : array<string|int, mixed>
-
Configuration
- $params : array<string|int, mixed>
-
Additional form parameters.
- $prefill : array<string|int, mixed>
-
Prefill form with these values.
Return values
array<string|int, mixed> —sanitizePrefill()
Validates prefill data and returns only the prefill values for enabled fields
protected
sanitizePrefill(array<string|int, mixed> $prefill) : array<string|int, mixed>
Parameters
- $prefill : array<string|int, mixed>
-
Prefill data
Return values
array<string|int, mixed> —sanitizeTranslationKey()
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
protected
sanitizeTranslationKey(string $key) : string
Parameters
- $key : string
-
Key to sanitize
Return values
string —Sanitized key
translateString()
Get translation for a string
protected
translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
- $rawStr : string
-
String to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $domain : string = 'default'
-
Text domain (omit for default)
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?