Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boltforms/ContentType and Date field type #3459

Closed
leocavalcante opened this issue Apr 28, 2015 · 6 comments
Closed

Boltforms/ContentType and Date field type #3459

leocavalcante opened this issue Apr 28, 2015 · 6 comments
Labels
bug A bug that has been verified

Comments

@leocavalcante
Copy link
Contributor

I was getting Catchable fatal error: Object of class DateTime could not be converted to string if a form field of type birthday linked to an ContentType field of type date.

The solution was:

Bolt\Content.php below line 287

if ($this->values[$key] instanceof \DateTime) {
    $this->values[$key] = $this->values[$key]->format('c');
}

Bolt\Extension\Bolt\BoltForms\Database.php below line 81

if ($value instanceof \DateTime) {
    $savedata[$key] = $value->format('c');
}

Not sure if is the best solution, but solved to me.

@bobdenotter
Copy link
Member

Hi @leocavalcante,

Could you give a bit more information about what you were doing, that caused these errors? I think your solution won't cause any side-effects, but we'd need to test those out.

@bobdenotter bobdenotter added bug A bug that has been verified 3rd party extension labels May 5, 2015
@leocavalcante
Copy link
Contributor Author

Sure!

To reproduce just link a Boltforms to a ContentType with a date/datetime type field:

contenttypes.yml:

form_requests:
  name: Form Requests
  singular_name: Form Request
  fields:
    title:
      type: text
    date:
      type: date
    file:
      type: file

boltforms.bolt.yml:

form_request:
  database:
    contenttype: form_requests
  fields:
    title:
      type: text
    date:
      type: date
    file:
      type: file
    submit:
      type: submit

index.twig

{{ boltforms('form_request') }}

Try to submit a request and got:

Catchable fatal error: Object of class DateTime could not be converted to string in C:\apache\htdocs\bolt-issue\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOStatement.php on line 91

I added a file type cause I think it wont will link properly to. Just as headsup.
At the end I created a extension to handle my form request on my actual project.

Changing to table:

form_request:
  database:
    #contenttype: form_requests
    table: bolt_form_requests

Doest not resolve, both Bolt\Storage->insertContent() and Bolt\Extension\Bolt\BoltForms\Database->writeToTable() are not handling different kinds of type.

@jadwigo
Copy link
Contributor

jadwigo commented May 11, 2015

This also needs the following in Bolt\Extension\Bolt\BoltForms\Email

https://github.com/GawainLynch/bolt-extension-boltforms/blob/master/src/Email.php#L96

And maybe the formatting must be some user readable format

        foreach($formdata as $key => $value) {
            if ($value instanceof \DateTime) {
                $formdata[$key] = $value->format('c');
            }
        }

@leocavalcante
Copy link
Contributor Author

Not sure if Bolt must know how to handle field values or if Boltforms should pass it already as strings. Sorry if issue is in wrong place.

@GwendolenLynch
Copy link
Contributor

The game is changing in that regard when we start work on Bolt 2.3… Watch this space 😁

For now we'll handle in BoltForms, @jadwigo PRed a fix today and I have merged it into the BF master branch and will tag a release soon(ish).

@GwendolenLynch
Copy link
Contributor

Closing as we're working around this now in BoltForms and as mentioned Bolt 2.3 has some significant updates on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug that has been verified
Projects
None yet
Development

No branches or pull requests

4 participants