TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Form\Utility\FormUtility Class Reference

Public Member Functions

 setConfiguration (Configuration $configuration)
 
 renderItem ($configuration, $type=null, $defaultMessage='')
 
 renderArrayItems (array &$arrayToRender=[])
 
 sanitizeNameAttribute ($name)
 
 sanitizeIdAttribute ($id)
 

Static Public Member Functions

static getObjectManager ()
 

Protected Attributes

 $configuration
 

Detailed Description

A utility for the form

Definition at line 23 of file FormUtility.php.

Member Function Documentation

◆ getObjectManager()

static TYPO3\CMS\Form\Utility\FormUtility::getObjectManager ( )
static

◆ renderArrayItems()

TYPO3\CMS\Form\Utility\FormUtility::renderArrayItems ( array &  $arrayToRender = [])

Render array values recursively as cObjects using the method renderItem.

Parameters
array$arrayToRender
Returns
array

Definition at line 205 of file FormUtility.php.

References TYPO3\CMS\Form\Utility\FormUtility\renderItem().

◆ renderItem()

TYPO3\CMS\Form\Utility\FormUtility::renderItem (   $configuration,
  $type = null,
  $defaultMessage = '' 
)

Render TypoScript values There are different variants. It is possible that the TypoScript which we want to render looks like this:

array( 'message' => 'TEXT', 'message.' => array( 'value' => 'blah' ) )

or in "short syntax" (the wizard writes some syntax partly)

array( 'message.' => array( 'value' => 'blah' ) )

or it is simply a string.

Furthermore we have 2 modes:

  • contentelement rendering is allowed
  • or contentelement rendering is not allowed

This method will take care of all scenarios and provide some fallbacks. Call this method always in the following way:

renderItem( $typoscript['itemToRender.'], $typoscript['itemToRender'], $optionalDefaultMessage )

You dont have to handle if is $typoscript['itemToRender.'] is set or not. This function determines this. This allows us to get the value of a TypoScript construct without knowing about "short syntax", only a string, a cObject, if cObject rendering is allowed and so on.

If contentelement rendering is allowed: If $type and $configuration are set render as an cObject.

If $type is set but $configuration is empty only return the value of $type.

If $type is empty and $configuration is an array ("short syntax") render the $configuration as content type TEXT.

If $type is empty and $configuration is a string render the value of $configuration like 10 = TEXT 10.value = $configuration.

If $type is empty and $configuration is empty return the $defaultMessage.

If contentelement rendering is not allowed: If $type is set but $configuration is empty only return the value of $type.

If $type is set and $configuration['value'] isset return the value of $configuration['value'].

If $type is set and $configuration['value'] is not set return the value of $defaultMessage.

If $type is empty and $configuration['value'] isset return the value of $configuration['value'].

If $type is empty and $configuration['value'] is not set return the value of $defaultMessage.

Parameters
mixed$configurationa string or a TypoScript array
NULL | string$typecObject type or simply a string value
string$defaultMessage
Returns
string

Definition at line 130 of file FormUtility.php.

References TYPO3\CMS\Form\Utility\FormUtility\$configuration, and $GLOBALS.

Referenced by TYPO3\CMS\Form\Utility\FormUtility\renderArrayItems().

◆ sanitizeIdAttribute()

TYPO3\CMS\Form\Utility\FormUtility::sanitizeIdAttribute (   $id)

If the id is not defined it is automatically generated using the following syntax: field-{element_counter} The id attribute will be transformed if it contains some non allowed characters:

  • spaces are changed into hyphens
  • if the id start with a integer then transform it to field-{integer}
  • remove all characters expect a-z A-Z 0-9 _ - : .
Parameters
string$id
Returns
string

Definition at line 261 of file FormUtility.php.

◆ sanitizeNameAttribute()

TYPO3\CMS\Form\Utility\FormUtility::sanitizeNameAttribute (   $name)

If the name is not defined it is automatically generated using the following syntax: id-{element_counter} The name attribute will be transformed if it contains some non allowed characters:

  • spaces are changed into hyphens
  • remove all characters except a-z A-Z 0-9 _ -
Parameters
string$name
Returns
string

Definition at line 238 of file FormUtility.php.

◆ setConfiguration()

TYPO3\CMS\Form\Utility\FormUtility::setConfiguration ( Configuration  $configuration)
Parameters
Configuration$configuration

Definition at line 45 of file FormUtility.php.

References TYPO3\CMS\Form\Utility\FormUtility\$configuration.

Member Data Documentation

◆ $configuration

TYPO3\CMS\Form\Utility\FormUtility::$configuration
protected