admin管理员组文章数量:1356751
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.
本文标签: TYPO3 12 Formssave custom field in databaseStack Overflow
版权声明:本文标题:TYPO3 12 Forms - save custom field in database - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744040923a2580647.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论