Gernott / mask

TYPO3 Extension Mask
https://www.facebook.com/typo3mask
GNU General Public License v2.0
130 stars 86 forks source link

backend preview for file fields like image etc. in repeatable content items does not work #439

Closed janamedick closed 3 years ago

janamedick commented 3 years ago

When trying to output a preview view of file fields like media, assets or image in repeatable content items (repetition > content) in the backend, an exception error is displayed ("PHP Warning: count(): Parameter must be an array or an object that implements Countable in..."). I suspect that the relation for the backend preview view is not resolved and instead only the number of stored images/media of the database field is displayed. In repetitions of type "inline" the preview view for file fields works fine.

nhovratov commented 3 years ago

Hey @janamedick ,

this should work. Which version of Mask do you use? Mask adds it to the data variable. Can you show me your backend preview html?

janamedick commented 3 years ago

Hey @nhovratov,

thanks for your fast reply. I can reproduce the error with a fresh TYPO3 installation: TYPO3 v10.4.21, Mask v7.0.26. I have created a very reduced example:

mask.json:

{
    "tt_content": {
        "elements": {
            "item": {
                "color": "#000000",
                "columns": [
                    "assets"
                ],
                "description": "",
                "icon": "",
                "key": "item",
                "label": "Item",
                "labels": [
                    "assets-field"
                ],
                "shortLabel": "item with assets-Field"
            },
            "wrapper": {
                "color": "#000000",
                "columns": [
                    "tx_mask_items"
                ],
                "description": "",
                "icon": "",
                "key": "wrapper",
                "label": "Wrapper",
                "labels": [
                    "Items"
                ],
                "shortLabel": ""
            }
        },
        "sql": {
            "tx_mask_items": {
                "tt_content": {
                    "tx_mask_items": "int(11) unsigned DEFAULT '0' NOT NULL"
                }
            }
        },
        "tca": {
            "assets": {
                "coreField": 1,
                "key": "assets",
                "name": "file"
            },
            "tx_mask_items": {
                "cTypes": [
                    "mask_item"
                ],
                "config": {
                    "appearance": {
                        "collapseAll": 1,
                        "enabledControls": {
                            "dragdrop": 1
                        },
                        "levelLinksPosition": "top",
                        "showAllLocalizationLink": 1,
                        "showPossibleLocalizationRecords": 1,
                        "useSortable": 1
                    },
                    "foreign_sortby": "sorting",
                    "foreign_table": "tt_content",
                    "overrideChildTca": {
                        "columns": {
                            "colPos": {
                                "config": {
                                    "default": 999
                                }
                            }
                        }
                    },
                    "type": "inline"
                },
                "description": "",
                "key": "items",
                "l10n_mode": "",
                "name": "content"
            }
        }
    }
}

Backend > Templates > Wrapper.html:

<f:if condition="{data.tx_mask_items}">
    <f:for each="{data.tx_mask_items}" as="data_item">
        <f:if condition="{data_item.assets}">
            <f:for each="{data_item.assets}" as="file">
                <f:image image="{file}" width="200" />
            </f:for>
        </f:if>
    </f:for>
</f:if>
nhovratov commented 3 years ago

Thanks, the example was really helpful! I even found another related bug. Thank you very much for your report.