Search code examples
formstypo3yamltyposcripttypo3-9.x

How can I override YAML settings of the TYPO3 Form Framework with TypoScript?


I've created a TYPO3 form via the form framework. Now I want to override some of these values with TypoScript. The form is stored in an extension, which can be used for every customer. The customer specific values should be overridden by my template extension which includes only customer specific settings. But the form framework doesn't use these settings. The TypoScript is loaded (Template Analyzer) and I cleared all caches.

I currently use TYPO3 Version 9.5.6 and the form framework has the same version.

This is a snippet from the form:

identifier: bewerbungsformular
label: Bewerbungsformular
type: Form
prototypeName: bewerbungen
finishers:
  -
    options:
      subject: 'Ihre Bewerbung'
      recipientAddress: '{text-email}'
      recipientName: 
      senderAddress: 
      senderName: Test Company 
      replyToAddress: ''
      carbonCopyAddress: ''
      blindCarbonCopyAddress: ''
      format: html
      attachUploads: false
    identifier: EmailToSender

And this is my setup.ts in my template extension. I found this snippet in the TYPO3 documentation. But there was no further explanation how the path to the value should look. I think something in the path is wrong:

plugin.tx_form {
    settings {
        yamlSettingsOverrides {

            #I think here is the mistake
            bewerbungsformular.finishers.EmailToSender.options.senderName = XYZ Company
        }
    }
}

Thanks.


Solution

  • For TypoScript overrides you need to use exactly the keys used in your form definition. Notice that lists are basically the same as hashes with numeric keys after conversion to an PHP array.

    So in YAML this:

    - foo
    - bar
    

    Is the same as this:

    0: foo
    1: bar
    

    Also you have used yamlSettingsOverrides which must be formDefinitionOverrides instead.

    So your code should look like this instead:

    plugin.tx_form {
        settings {
            formDefinitionOverrides {
                bewerbungsformular {
                    finishers {
                        0 {
                            options {
                                senderName = XYZ Company
                            }
                        }
                    }
                }
            }
        }
    }
    

    As you can see, numeric indices are not as speaking as named indices. So if you don't plan to use the form editor in the backend to make further changes to your form definition you can directly use YAML hashes instead of lists:

    identifier: bewerbungsformular
    # ...
    finishers:
      mailToSender:
        identifier: EmailToSender
        options:
          # ...
    

    Then your TypoScript overrides could look like this:

    plugin.tx_form {
        settings {
            formDefinitionOverrides {
                bewerbungsformular {
                    finishers {
                        mailToSender {
                            options {
                                senderName = XYZ Company
                            }
                        }
                    }
                }
            }
        }
    }