CountrySelectViewHelper extends AbstractFormFieldViewHelper
Renders a :html:`<select>` tag with all available countries as options.
Examples
Basic usage
::
<f:form.countrySelect name="country" value="{defaultCountry}" />
Output::
Prioritize countries
Define a list of countries which should be listed as first options in the form element::
<f:form.countrySelect name="country" value="AT" prioritizedCountries="{0: 'DE', 1: 'AT', 2: 'CH'}" />
Additionally, Austria is pre-selected.
Display another language
A combination of optionLabelField and alternativeLanguage is possible. For instance, if you want to show the localized official names but not in your default language but in French. You can achieve this by using the following combination::
<f:form.countrySelect name="country" optionLabelField="localizedOfficialName" alternativeLanguage="fr" sortByOptionLabel="true" />
Bind an object
You can also use the "property" attribute if you have bound an object to the form.
See :ref:<f:form> <typo3-fluid-form>
for more documentation.
Table of Contents
Properties
- $configurationManager : ConfigurationManagerInterface
- $persistenceManager : PersistenceManagerInterface
- $respectSubmittedDataValue : bool
- $tagName : string
Methods
- getRespectSubmittedDataValue() : bool
- Getting the current configuration for respectSubmittedDataValue.
- initializeArguments() : void
- injectConfigurationManager() : void
- injectPersistenceManager() : void
- render() : string
- setRespectSubmittedDataValue() : void
- Define respectSubmittedDataValue to enable or disable the usage of the submitted values in the viewhelper.
- addAdditionalIdentityPropertiesIfNeeded() : void
- Add additional identity properties in case the current property is hierarchical (of the form "bla.blubb").
- convertToPlainValue() : mixed
- Converts an arbitrary value to a plain value
- createOptions() : array<string, string>
- getCountryList() : array<string|int, Country>
- getLastSubmittedFormData() : mixed
- Get the form data which has last been submitted; only returns valid data in case a property mapping error has occurred. Check with hasMappingErrorOccurred() before!
- getMappingResultsForProperty() : Result
- Get errors for the property and form name of this ViewHelper
- getName() : string
- Get the name of this form element.
- getNameWithoutPrefix() : string
- Get the name of this form element, without prefix.
- getPropertyValue() : mixed
- Get the current property of the object bound to this form.
- getRequest() : RequestInterface
- Shortcut for retrieving the request from the controller context
- getValueAttribute() : mixed
- Returns the current value of this Form ViewHelper and converts it to an identifier string in case it's an object The value is determined as follows: * If property mapping errors occurred and the form is re-displayed, the *last submitted* value is returned * Else the bound property is returned (only in objectAccessor-mode) * As fallback the "value" argument of this ViewHelper is used
- getValueFromSubmittedFormData() : mixed
- If property mapping errors occurred and the form is re-displayed, the *last submitted* value is returned by this method.
- hasMappingErrorOccurred() : bool
- Checks if a property mapping error has occurred in the last request.
- isObjectAccessorMode() : bool
- Internal method which checks if we should evaluate a domain object or just output arguments['name'] and arguments['value']. Returns true if domoin object should be evaluated.
- prefixFieldName() : string
- Prefixes / namespaces the given name with the form field prefix
- registerFieldNameForFormTokenGeneration() : void
- Register a field name for inclusion in the HMAC / Form Token generation
- renderHiddenFieldForEmptyValue() : string
- Renders a hidden field with the same name as the element, to make sure the empty value is submitted in case nothing is selected. This is needed for checkbox and multiple select fields
- renderHiddenIdentityField() : string
- Renders a hidden form field containing the technical identity of the given object.
- renderOptionTag() : string
- Render one option tag
- renderPrependOptionTag() : string
- Render prepended option tag
- setErrorClassAttribute() : void
- Add a CSS class if this ViewHelper has errors
- translate() : string
Properties
$configurationManager
protected
ConfigurationManagerInterface
$configurationManager
$persistenceManager
protected
PersistenceManagerInterface
$persistenceManager
$respectSubmittedDataValue
protected
bool
$respectSubmittedDataValue
= false
$tagName
protected
string
$tagName
= 'select'
Methods
getRespectSubmittedDataValue()
Getting the current configuration for respectSubmittedDataValue.
public
getRespectSubmittedDataValue() : bool
Return values
boolinitializeArguments()
public
initializeArguments() : void
injectConfigurationManager()
public
injectConfigurationManager(ConfigurationManagerInterface $configurationManager) : void
Parameters
- $configurationManager : ConfigurationManagerInterface
injectPersistenceManager()
public
injectPersistenceManager(PersistenceManagerInterface $persistenceManager) : void
Parameters
- $persistenceManager : PersistenceManagerInterface
render()
public
render() : string
Return values
stringsetRespectSubmittedDataValue()
Define respectSubmittedDataValue to enable or disable the usage of the submitted values in the viewhelper.
public
setRespectSubmittedDataValue(bool $respectSubmittedDataValue) : void
Parameters
- $respectSubmittedDataValue : bool
addAdditionalIdentityPropertiesIfNeeded()
Add additional identity properties in case the current property is hierarchical (of the form "bla.blubb").
protected
addAdditionalIdentityPropertiesIfNeeded() : void
Then, [bla][__identity] has to be generated as well.
convertToPlainValue()
Converts an arbitrary value to a plain value
protected
convertToPlainValue(mixed $value) : mixed
Parameters
- $value : mixed
-
The value to convert
createOptions()
protected
createOptions(array<string|int, Country> $countries) : array<string, string>
Parameters
- $countries : array<string|int, Country>
Return values
array<string, string>getCountryList()
protected
getCountryList() : array<string|int, Country>
Return values
array<string|int, Country>getLastSubmittedFormData()
Get the form data which has last been submitted; only returns valid data in case a property mapping error has occurred. Check with hasMappingErrorOccurred() before!
protected
getLastSubmittedFormData() : mixed
getMappingResultsForProperty()
Get errors for the property and form name of this ViewHelper
protected
getMappingResultsForProperty() : Result
Return values
ResultgetName()
Get the name of this form element.
protected
getName() : string
Either returns arguments['name'], or the correct name for Object Access. In case property is something like bla.blubb (hierarchical), then [bla][blubb] is generated.
Return values
stringgetNameWithoutPrefix()
Get the name of this form element, without prefix.
protected
getNameWithoutPrefix() : string
Return values
stringgetPropertyValue()
Get the current property of the object bound to this form.
protected
getPropertyValue() : mixed
Return values
mixed —Value
getRequest()
Shortcut for retrieving the request from the controller context
protected
getRequest() : RequestInterface
Return values
RequestInterface —The extbase (!) request. All these VH's are extbase-only.
getValueAttribute()
Returns the current value of this Form ViewHelper and converts it to an identifier string in case it's an object The value is determined as follows: * If property mapping errors occurred and the form is re-displayed, the *last submitted* value is returned * Else the bound property is returned (only in objectAccessor-mode) * As fallback the "value" argument of this ViewHelper is used
protected
getValueAttribute() : mixed
Note: This method should not be used for form elements that must not change the value attribute, e.g. (radio) buttons and checkboxes.
Return values
mixed —Value
getValueFromSubmittedFormData()
If property mapping errors occurred and the form is re-displayed, the *last submitted* value is returned by this method.
protected
getValueFromSubmittedFormData(mixed $value) : mixed
Note: This method should not be used for form elements that must not change the value attribute, e.g. (radio) buttons and checkboxes. The default behaviour is not to use this method. You need to set respectSubmittedDataValue to TRUE to enable the form data handling for the viewhelper.
Parameters
- $value : mixed
Return values
mixed —Value
hasMappingErrorOccurred()
Checks if a property mapping error has occurred in the last request.
protected
hasMappingErrorOccurred() : bool
Return values
boolisObjectAccessorMode()
Internal method which checks if we should evaluate a domain object or just output arguments['name'] and arguments['value']. Returns true if domoin object should be evaluated.
protected
isObjectAccessorMode() : bool
Return values
boolprefixFieldName()
Prefixes / namespaces the given name with the form field prefix
protected
prefixFieldName(string $fieldName) : string
Parameters
- $fieldName : string
Return values
stringregisterFieldNameForFormTokenGeneration()
Register a field name for inclusion in the HMAC / Form Token generation
protected
registerFieldNameForFormTokenGeneration(string $fieldName) : void
Parameters
- $fieldName : string
renderHiddenFieldForEmptyValue()
Renders a hidden field with the same name as the element, to make sure the empty value is submitted in case nothing is selected. This is needed for checkbox and multiple select fields
protected
renderHiddenFieldForEmptyValue() : string
Return values
stringrenderHiddenIdentityField()
Renders a hidden form field containing the technical identity of the given object.
protected
renderHiddenIdentityField(mixed $object, string|null $name) : string
Parameters
- $object : mixed
-
Object to create the identity field for. Non-objects are ignored.
- $name : string|null
-
Name
Tags
Return values
string —A hidden field containing the Identity (uid) of the given object
renderOptionTag()
Render one option tag
protected
renderOptionTag(string $value, string $label, bool $isSelected) : string
Parameters
- $value : string
-
value attribute of the option tag (will be escaped)
- $label : string
-
content of the option tag (will be escaped)
- $isSelected : bool
-
specifies whether to add selected attribute
Return values
string —the rendered option tag
renderPrependOptionTag()
Render prepended option tag
protected
renderPrependOptionTag() : string
Return values
stringsetErrorClassAttribute()
Add a CSS class if this ViewHelper has errors
protected
setErrorClassAttribute() : void
translate()
protected
translate(string $label) : string
Parameters
- $label : string