Search code examples
shopware6shopware6-app

Shopware 6: Media upload/field as custom field in app-manifest


Can i use a media field as custom field in a app manifest?

The following example is not working:

<custom-field-set>
            ...
            <related-entities>
                <category/>
            </related-entities>
            <fields>
           
                <many-to-one name="vendorname-image" reference="media" store-api-aware="true" on-delete="set-null" >
                    <position>2</position>
                    <label>Image for megamenu</label>
                    <label lang="de-DE">Bild für Megamenü</label>
                </many-to-one>
            </fields>
        </custom-field-set>

Solution

  • You're mixing up elements for fields of custom entities and elements for actual custom fields. The correct element would be media-selection for a custom field that contains the id of a media entity.

    <manifest ...>
        <custom-fields>
            <custom-field-set>
                <name>swag_example_set</name>
                <label>Example Set</label>
                <related-entities>
                    <category/>
                </related-entities>
                <fields>
                    <media-selection name="vendorname_image">
                        <position>2</position>
                        <label>Image for megamenu</label>
                        <label lang="de-DE">Bild für Megamenü</label>
                    </media-selection>
                </fields>
            </custom-field-set>
        </custom-fields>
    </manifest>