Bug #88899

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

Added by Dirk Steffens 3 months ago. Updated 19 days ago.

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

0%

TYPO3 Version:
8
PHP Version:
7.0
Tags:
DatePicker finisher parseOption DateTime CodingNight
Complexity:
medium
Is Regression:
Sprint Focus:

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.

History

#1 Updated by Susanne Moog 3 months ago

  • Tags changed from DatePicker finisher parseOption DateTime to DatePicker finisher parseOption DateTime CodingNight

#2 Updated by Bjoern Jacob 3 months ago

Today, this issue was discussed on Slack within the #ext-form channel. Here's the link: https://typo3.slack.com/archives/C093RB4P9/p1564708838072600

It comes from a datepicker-element in the contact-form. Results in type DateTime. The debugger is just open to see this very clear.

Alright, that explains it. Apparently this usecase is not yet supported. You could work around this by manipulating the birthday form value to convert it into a date string (with your preferred format) before calling parseOption() for the message.
For this you can use $this->finisherContext->getFormRuntime()->getFormState()->setFormValue('birthday', $formattedDate).

Edit: I just realized that the author of the ticket is the same person who has discussed this on the channel :)

#3 Updated by Pascal Naujoks 19 days ago

  • Tracker changed from Feature to Bug
  • TYPO3 Version set to 8
  • PHP Version changed from 7.2 to 7.0

Can reproduce in TYPO3 8.7.27 when using the datepicker in the E-Mail finisher as the subject like "New reservation on {datepicker-1}"

Also available in: Atom PDF