Good day to you.
I would like to save my custom field in "forms" in the database but it's not working as intended. So far I got this nice yaml and I got my nice little textfield in the backend.
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
formEditor:
editors:
900:
# Extend finisher drop down
selectOptions:
35:
value: 'CustomFinisherSaveToDatabase'
label: 'Custom SaveToDatabase'
propertyCollections:
finishers:
# add finisher fields
25:
identifier: 'CustomFinisherSaveToDatabase'
editors:
100:
# add expandable header area
identifier: header
label: "Custom SaveToDatabase"
templateName: Inspector-CollectionElementHeaderEditor
105:
# add remove button
identifier: removeButton
templateName: Inspector-RemoveElementEditor
110:
# add a new custom field defined as a TextEditor
identifier: 'mycustomfield'
templateName: 'Inspector-TextEditor'
label: 'Custom Field'
propertyPath: 'options.mycustomfield'
propertyValidators:
10: 'NotEmpty'
finishersDefinition:
CustomFinisherSaveToDatabase:
implementationClassName: TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher
# my mycustomfield is available in the backend, so far so good.
FormEngine:
label: 'Custom SaveToDatabase'
elements:
mycustomfield:
identifier: 'mycustomfieldidentifier'
label: 'Custom Field'
config:
type: 'text'
formEditor:
iconIdentifier: 'form-finisher'
label: 'Custom SaveToDatabase'
predefinedDefaults:
options:
table: 'my_table'
mode: insert
databaseColumnMappings:
# save the value of mycustomfield in database
tablefield1:
value: '{mycustomfield}'
tablefield2:
value: '{mycustomfieldidentifier}'
But I'm literally saving the words "{mycustomfield}" and "{mycustomfieldidentifier}" in the database fields, not the value itself. Even without the quotation marks or the brackets, it doesn't work. Am I missing something here, or is that not possible?
Update: According to Mathias Brodala (thanks for the comment) I tried "elements" and changed my code to this:
finishersDefinition:
CustomFinisherSaveToDatabase:
implementationClassName: TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher
# my mycustomfield is available in the backend, so far so good.
FormEngine:
label: 'Custom SaveToDatabase'
elements:
mycustomfield:
identifier: 'mycustomfieldidentifier'
label: 'Custom Field'
config:
type: 'text'
formEditor:
iconIdentifier: 'form-finisher'
label: 'Custom SaveToDatabase'
predefinedDefaults:
options:
table: 'my_table'
mode: insert
elements:
mycustomfield:
mapOnDatabaseColumn: 'tablefield1'
mycustomfieldidentifier:
mapOnDatabaseColumn: 'tablefield2'
But it still doesn't work. Either I made another mistake or I need the "parseOption" but don't know (yet) how to include it.
Second update: Ok, I got some kind of workaround....I am not very proud of it but it does the job.
So I added my own
class CustomSaveToDatabaseFinisher extends AbstractFinisher
and copied the whole original code from "SaveToDatabaseFinisher". Then I added these lines
$databaseData[$elementsConfiguration[$elementIdentifier]['mapOnDatabaseColumn']] = $elementValue;
}
// custom fields added here
$databaseData[$elementsConfiguration['mycustomfield']['mapOnDatabaseColumn']] = $this->parseOption('mycustomfield');
return $databaseData;
It does the trick but I am not 100% satisfied with it....on the other hand I still don't know why "mycustomfield" is still ignored and I am open for suggestions. So far this is better than nothing. ^^
Thanks!
TZP
Good day to you.
I would like to save my custom field in "forms" in the database but it's not working as intended. So far I got this nice yaml and I got my nice little textfield in the backend.
TYPO3:
CMS:
Form:
prototypes:
standard:
formElementsDefinition:
Form:
formEditor:
editors:
900:
# Extend finisher drop down
selectOptions:
35:
value: 'CustomFinisherSaveToDatabase'
label: 'Custom SaveToDatabase'
propertyCollections:
finishers:
# add finisher fields
25:
identifier: 'CustomFinisherSaveToDatabase'
editors:
100:
# add expandable header area
identifier: header
label: "Custom SaveToDatabase"
templateName: Inspector-CollectionElementHeaderEditor
105:
# add remove button
identifier: removeButton
templateName: Inspector-RemoveElementEditor
110:
# add a new custom field defined as a TextEditor
identifier: 'mycustomfield'
templateName: 'Inspector-TextEditor'
label: 'Custom Field'
propertyPath: 'options.mycustomfield'
propertyValidators:
10: 'NotEmpty'
finishersDefinition:
CustomFinisherSaveToDatabase:
implementationClassName: TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher
# my mycustomfield is available in the backend, so far so good.
FormEngine:
label: 'Custom SaveToDatabase'
elements:
mycustomfield:
identifier: 'mycustomfieldidentifier'
label: 'Custom Field'
config:
type: 'text'
formEditor:
iconIdentifier: 'form-finisher'
label: 'Custom SaveToDatabase'
predefinedDefaults:
options:
table: 'my_table'
mode: insert
databaseColumnMappings:
# save the value of mycustomfield in database
tablefield1:
value: '{mycustomfield}'
tablefield2:
value: '{mycustomfieldidentifier}'
But I'm literally saving the words "{mycustomfield}" and "{mycustomfieldidentifier}" in the database fields, not the value itself. Even without the quotation marks or the brackets, it doesn't work. Am I missing something here, or is that not possible?
Update: According to Mathias Brodala (thanks for the comment) I tried "elements" and changed my code to this:
finishersDefinition:
CustomFinisherSaveToDatabase:
implementationClassName: TYPO3\CMS\Form\Domain\Finishers\SaveToDatabaseFinisher
# my mycustomfield is available in the backend, so far so good.
FormEngine:
label: 'Custom SaveToDatabase'
elements:
mycustomfield:
identifier: 'mycustomfieldidentifier'
label: 'Custom Field'
config:
type: 'text'
formEditor:
iconIdentifier: 'form-finisher'
label: 'Custom SaveToDatabase'
predefinedDefaults:
options:
table: 'my_table'
mode: insert
elements:
mycustomfield:
mapOnDatabaseColumn: 'tablefield1'
mycustomfieldidentifier:
mapOnDatabaseColumn: 'tablefield2'
But it still doesn't work. Either I made another mistake or I need the "parseOption" but don't know (yet) how to include it.
Second update: Ok, I got some kind of workaround....I am not very proud of it but it does the job.
So I added my own
class CustomSaveToDatabaseFinisher extends AbstractFinisher
and copied the whole original code from "SaveToDatabaseFinisher". Then I added these lines
$databaseData[$elementsConfiguration[$elementIdentifier]['mapOnDatabaseColumn']] = $elementValue;
}
// custom fields added here
$databaseData[$elementsConfiguration['mycustomfield']['mapOnDatabaseColumn']] = $this->parseOption('mycustomfield');
return $databaseData;
It does the trick but I am not 100% satisfied with it....on the other hand I still don't know why "mycustomfield" is still ignored and I am open for suggestions. So far this is better than nothing. ^^
Thanks!
TZP
Share Improve this question edited Mar 31 at 13:47 TZP asked Mar 28 at 11:19 TZPTZP 535 bronze badges1 Answer
Reset to default 1You need to use elements
instead which is meant for mapping form element values to DB columns.
Compared to that the databaseColumnMappings
option is meant for static values instead.