0

I am looking for an example for simple use of single_media_upload in SULU AdminUI.

I have a player form, and it has single_media_selection type of field, and it works OK.

Now, how can I use single_media_upload, because, when I replace it instead of single_media_selection, it shows not picture in form after save (but it saves image).

<property name="photo" type="single_media_selection" colspan="4" >
            <meta>
                <title>playerinfo.playerimage</title>
            </meta>
            <params>
                <param name="types" value="image"/>
            </params>
        </property>

I replace with

<property name="photo" type="single_media_upload" colspan="4" spaceAfter="2">
                <params>
                    <param name="upload_text">
                        <meta>
                            <info_text>app.player_info_upload</info_text>
                        </meta>
                    </param>
                    <param name="skin" value="default"/>
                    <param name="empty_icon" value="su-user"/>
                    <param
                        name="collection_id"
                        type="expression"
                        value="service('sulu_media.system_collections.manager').getSystemCollection('sulu_media')"
                    />
                </params>
            </property>

In Entity itself, field is MediaInterface type.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

0

The single_media_upload field-type is not interchangeable with the single_media_selection type. It was implemented for managing the avatar/logo of the built-in contact/account entity and was not optimized for other usecases yet. At the moment, the single_media_upload creates a new media version for the selected media entity rather than creating a separate media entity when uploading a file. This behaviour differs substantially from the single_media_selection and might not fit your usecase. This is also the reason why the field-type is not listed in the Sulu documentation yet.

That said, the reason for your problem is likely that the single_media_upload field-type uses a different data format than the single_media_selection. In general, the field-types of the Sulu form view expect that your API returns the data in the same format as it is sent to the server when submitting the form (see the Form configuration section in the Sulu documentation). You can see the data that is sent to the server by inspecting the request that is made when pressing the save button in the network panel development tools of your browser.

In the case of the single_media_upload field-type, the data that is sent to the server looks like this:

{
  "id": 33,
  "url": "/media/33/download/photo-1535683939029-0030b4de2382.jpeg?v=1",
  "thumbnails": {
    "sulu-400x400": "/uploads/media/sulu-400x400/03/33-photo-1535683939029-0030b4de2382.jpg?v=1-0",
    ...
  }
}

If you want to use the field-type in the form of your custom entity, you need to adjust your controller (or the serialization of your entity) to match this format.

nnatter
  • 111
  • 3