BoltTranslate / Translate

Provides translation for contenttypes.
Other
43 stars 37 forks source link

[BUG] saving with templatefields throws: Warning: Invalid argument supplied for foreach() #201

Closed zomars closed 5 years ago

zomars commented 5 years ago

Maybe I'm missing something here.

Details

Reproduction

On theme.yml:


templatefields:
    products.twig:
        foot_title:
            type: text
            translatable: true
        foot_subtitle:
            type: text
            translatable: true
        foot_content:
            type: html
            translatable: true
        foot_image:
            type: image

On my contenttype.yml:

pages:
    name: Pages
    singular_name: Page
    fields:
        title:
            type: text
            class: large
            group: content
        slug:
            type: slug
            uses: title
        subtitle:
            type: text
            class: large
        image:
            type: image
            placeholder: https://source.unsplash.com/1280x768/?business,workplace/__random__
        description:
            type: text
            class: large
            group: Explorer
        textlink:
            type: text
            label: "Text link"
        contentlink:
            type: text
            label: "Page link"
        template:
            type: templateselect
            filter: '*.twig'
        locale:
            type: locale
            group: content
        esdata:
            type: hidden
        esslug:
            type: locale_data
            index: true
        endata:
            type: hidden
        enslug:
            type: locale_data
            index: true
    recordsperpage: 4
    viewless: true

image

This is the full response:

{
    "success": false,
    "code": 500,
    "error": {
        "type": "\\ContextError",
        "file": "extensions\/vendor\/animal\/translate\/src\/EventListener\/StorageListener.php",
        "line": 269,
        "message": "Warning: Invalid argument supplied for foreach()"
    }
}

And full headers:

POST /bolt/editcontent/pages/1?_locale=en HTTP/1.1
Host: viva-organica-cms.localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Referer: http://viva-organica-cms.localhost/bolt/editcontent/pages/1?_locale=en
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
DNT: 1
Connection: keep-alive
Cookie: bolt_session_3ae7df4b344d1122d8faa58950eb92c9=d75c6e69fafacbc41fcb61a354; bolt_authtoken_3ae7df4b344d1122d8faa58950eb92c9=ea0004108fd226dd89695a7cfac0f06389bee479f4fbfe63b58885dbbec0622d
cache-control: no-cache
Postman-Token: 89bd4cd6-2980-4b3a-acd6-985a17ced3f5
content_edit%5B_token%5D=--cYTRLwAVmok-sMgGC4MgR6kJdzTJGEKcXmGZo1a1E&editreferrer=&contenttype=pages&title=Best+flavored+products&slug=products&subtitle=All+our+work+is+focused+on+achieving+the+best+flavor.&image%5Bfile%5D=2019-01%2Fflavored-products.jpg&_locale=en&no_locale_hydrate=true&esdata=&endata=&description=All+our+work+is+focused+on+achieving+the+best+flavor.&textlink=View+products&contentlink=%2Fproducts&template=products.twig&templatefields%5Bfoot_title%5D=&templatefields%5Bfoot_subtitle%5D=&templatefields%5Bfoot_content%5D=&templatefields%5Bfoot_image%5D%5Bfile%5D=&id=1&status=published&datepublish=2019-01-28+15%3A51%3A55&datedepublish=&ownerid=1&_live-editor-preview=&content_edit%5Bsave%5D=undefined------WebKitFormBoundary7MA4YWxkTrZu0gW--
zomars commented 5 years ago

Ok, I've figured it out. Posting here for reference.

The problem was that my contenttype had no fields with the translateable: true property.