‪TYPO3CMS  ‪main
TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher Class Reference
Inheritance diagram for TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher:
TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher TYPO3\CMS\Form\Domain\Finishers\FinisherInterface

Protected Member Functions

 executeInternal ()
 
array prepareData (array $elementsConfiguration, array $databaseData)
 
 process (int $iterationCount)
 
 saveToDatabase (array $databaseData, string $table, int $iterationCount)
 
 throwExceptionOnInconsistentConfiguration ()
 
 getFormValues ()
 
FormElementInterface null getElementByIdentifier (string $elementIdentifier)
 
- ‪Protected Member Functions inherited from ‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
string array int null parseOption (string $optionName)
 
array string translateFinisherOption ( $subject, FormRuntime $formRuntime, string $optionName, $optionValue, array $translationOptions)
 
mixed substituteRuntimeReferences ($needle, FormRuntime $formRuntime)
 
int string array resolveRuntimeReference (string $property, FormRuntime $formRuntime)
 
 getTypoScriptFrontendController ()
 

Protected Attributes

array $defaultOptions
 
TYPO3 CMS Core Database Connection $databaseConnection
 
- ‪Protected Attributes inherited from ‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
string $finisherIdentifier = ''
 
string $shortFinisherIdentifier = ''
 
array $options = array( )
 
array $defaultOptions = array( )
 
TYPO3 CMS Form Domain Finishers FinisherContext $finisherContext
 

Additional Inherited Members

- ‪Public Member Functions inherited from ‪TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
 setFinisherIdentifier (string $finisherIdentifier)
 
 getFinisherIdentifier ()
 
 setOptions (array $options)
 
 setOption (string $optionName, $optionValue)
 
string null execute (FinisherContext $finisherContext)
 
 isEnabled ()
 

Detailed Description

This finisher saves the data from a submitted form into a database table.

Configuration

options.table (mandatory)

Save or update values into this table

options.mode (default: insert)

Possible values are 'insert' or 'update'.

insert: will create a new database row with the values from the submitted form and/or some predefined values. See options.elements and options.databaseFieldMappings update: will update a given database row with the values from the submitted form and/or some predefined values. 'options.whereClause' is then required.

options.whereClause

This where clause will be used for a database update action

options.elements

Use this to map form element values to existing database columns. Each key within options.elements has to match with a form element identifier within your form definition. The value for each key within options.elements is an array with additional information.

options.elements.<elementIdentifier>.mapOnDatabaseColumn (mandatory)

The value from the submitted form element with the identifier '<elementIdentifier>' will be written into this database column

options.elements.<elementIdentifier>.skipIfValueIsEmpty (default: false)

Set this to true if the database column should not be written if the value from the submitted form element with the identifier '<elementIdentifier>' is empty (think about password fields etc.)

options.elements.<elementIdentifier>.saveFileIdentifierInsteadOfUid (default: false)

This setting only rules for form elements which creates a FAL object like FileUpload or ImageUpload. By default, the uid of the FAL object will be written into the database column. Set this to true if you want to store the FAL identifier (1:/user_uploads/some_uploaded_pic.jpg) instead.

options.databaseColumnMappings

Use this to map database columns to static values (which can be made dynamic through typoscript overrides of course). Each key within options.databaseColumnMappings has to match with a existing database column. The value for each key within options.databaseColumnMappings is an array with additional information.

This mapping is done before the options.elements mapping. This means if you map a database column to a value through options.databaseColumnMappings and map a submitted form element value to the same database column, the submitted form element value will override the value you set within options.databaseColumnMappings.

options.databaseColumnMappings.<databaseColumnName>.value

The value which will be written to the database column. You can use the FormRuntime accessor feature to access every getable property from the TYPO3\CMS\Form\Domain\Runtime\FormRuntime Read the description within TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher::parseOption In short: use something like {<elementIdentifier>} to get the value from the submitted form element with the identifier <elementIdentifier>

Don't be confused. If you use the FormRuntime accessor feature within options.databaseColumnMappings, the functionality is nearly equal to the the options.elements configuration.

options.databaseColumnMappings.<databaseColumnName>.skipIfValueIsEmpty (default: false)

Set this to true if the database column should not be written if the value from options.databaseColumnMappings.<databaseColumnName>.value is empty.

Example

finishers:

  • ‪identifier: SaveToDatabase options: table: 'fe_users' mode: update whereClause: uid: 1 databaseColumnMappings: pid: value: 1 elements: text-1: mapOnDatabaseColumn: 'first_name' text-2: mapOnDatabaseColumn: 'last_name' text-3: mapOnDatabaseColumn: 'username' advancedpassword-1: mapOnDatabaseColumn: 'password' skipIfValueIsEmpty: true

Multiple database operations

You can write options as an array to perform multiple database operations.

finishers:

  • ‪identifier: SaveToDatabase options: 1: table: 'my_table' mode: insert databaseColumnMappings: some_column: value: 'cool' 2: table: 'my_other_table' mode: update whereClause: pid: 1 databaseColumnMappings: some_other_column: value: '{SaveToDatabase.insertedUids.1}'

This would perform 2 database operations. One insert and one update. You can access the inserted uids with '{SaveToDatabase.insertedUids.<theArrayKeyNumberWithinOptions>}' If you perform an insert operation, the value of the inserted database row will be stored within the FinisherVariableProvider. <theArrayKeyNumberWithinOptions> references to the numeric key within options within which the insert operation is executed.

Scope: frontend

Definition at line 174 of file SaveToDatabaseFinisher.php.

Member Function Documentation

◆ executeInternal()

TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher::executeInternal ( )
protected

◆ getElementByIdentifier()

FormElementInterface null TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher::getElementByIdentifier ( string  $elementIdentifier)
protected

Returns a form element object for a given identifier.

Returns
‪FormElementInterface|null

Definition at line 355 of file SaveToDatabaseFinisher.php.

Referenced by TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher\prepareData().

◆ getFormValues()

TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher::getFormValues ( )
protected

Returns the values of the submitted form

Definition at line 345 of file SaveToDatabaseFinisher.php.

Referenced by TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher\prepareData().

◆ prepareData()

array TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher::prepareData ( array  $elementsConfiguration,
array  $databaseData 
)
protected

◆ process()

◆ saveToDatabase()

TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher::saveToDatabase ( array  $databaseData,
string  $table,
int  $iterationCount 
)
protected

Save or insert the values from $databaseData into the table $table

Definition at line 298 of file SaveToDatabaseFinisher.php.

References TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption().

Referenced by TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher\process().

◆ throwExceptionOnInconsistentConfiguration()

TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher::throwExceptionOnInconsistentConfiguration ( )
protected

Throws an exception if some inconsistent configuration are detected.

Exceptions
FinisherException

Definition at line 329 of file SaveToDatabaseFinisher.php.

References TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher\parseOption().

Referenced by TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher\process().

Member Data Documentation

◆ $databaseConnection

TYPO3 CMS Core Database Connection TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher::$databaseConnection
protected

Definition at line 188 of file SaveToDatabaseFinisher.php.

◆ $defaultOptions

array TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher::$defaultOptions
protected
Initial value:
= array(
'table' => null,
'mode' => 'insert',
'whereClause' => [],
'elements' => [],
'databaseColumnMappings' => [],
)

Definition at line 178 of file SaveToDatabaseFinisher.php.