Project

General

Profile

Actions

Bug #88899

closed

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

Added by Dirk Steffens over 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Should have
Category:
Form Framework
Start date:
2019-08-02
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.0
Tags:
DatePicker finisher parseOption DateTime CodingNight
Complexity:
medium
Is Regression:
Sprint Focus:
Remote Sprint

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.

Actions

Also available in: Atom PDF