Issue Bug Closed

#88899DatePicker-Field used in finisher option fails with PHP-conversion Error

Dirk Steffens 08/02/19, 18:34 updated 12/23/19, 22:45

Description

A simple form with only a datepicker-field crashes in finisher:

#1476107295: PHP Catchable Fatal Error: Object of class DateTime could not be converted to string in /typo3_src/typo3/sysext/form/Classes/Domain/Finishers/AbstractFinisher.php line 319

In ‘Subject’ in (e.g.) emailFinisher there is a formelement identifier from the Datepicker-field together with a little bit other text in the same field.

This is the yaml-code of an example to reproduce it:

renderingOptions:
  submitButtonLabel: Submit
type: Form
identifier: datePickerTest
label: DatePickerTest
prototypeName: standard
finishers:
  -
    options:
      subject: 'prepend{datepicker-1}append'
      recipientAddress: recipient@anydomain.de
      recipientName: ''
      senderAddress: sender@anydomain.de
      senderName: ''
      replyToAddress: ''
      carbonCopyAddress: ''
      blindCarbonCopyAddress: ''
      format: html
      attachUploads: true
    identifier: EmailToSender
renderables:
  -
    renderingOptions:
      previousButtonLabel: 'Previous step'
      nextButtonLabel: 'Next step'
    type: Page
    identifier: page-1
    label: Step
    renderables:
      -
        properties:
          dateFormat: Y-m-d
          enableDatePicker: true
          displayTimeSelector: false
        type: DatePicker
        identifier: datepicker-1
        label: 'Date picker'

The Problem is with: subject: ‘prepend{datepicker-1}append’
Without prepend / append- string this error does not happen. Instead there is another Error which is not discussed here.

Since the error happens in parseOption() it is usefull to replace the DateTime object with a Text-equivalent before calling parseOption().
This can be done with the following workaround:

foreach ($this->finisherContext->getFormValues() as $key => $formvalue){
    if (is_object($formvalue) && get_class($formvalue)=="DateTime"){
        $format = $this->finisherContext->getFormRuntime()->getFormDefinition()->getElementByIdentifier('from')->getProperties()['dateFormat'];
        $this->finisherContext->getFormRuntime()->getFormState()->setFormValue($key, $formvalue->format($format));
    }
}

Therfor one has to build an own finisher or to use a hook.

Reviews 1