Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim Almond 8 posts 88 karma points
    Jan 17, 2018 @ 12:23
    Tim Almond
    0

    Selecting a Media Folder for an Item

    Is there a simple way to automatically assign a folder for media for a content node? So, if a user is editing an item (for instance id 21), the media picker will select images/21 by default?

  • Søren Tidmand 118 posts 355 karma points
    Jan 17, 2018 @ 13:24
    Søren Tidmand
    0

    Hi Tim,

    Since the id of a media folder is given "sequencially" when created and thereby can't be identical to the id of the content node the exact scenario is not possible.

    But it would be possible if you made an action handler that would automatically

    • create a new media folder WHEN you create a new node (for example of the doctype News Item)
    • save the ID of the newly created media folder to a property on the content node,
    • and when rendering this node you would check for images in the media folder and show them if not empty.

    In this example you need to have a property on the content node where Umbraco will store the ID of the media folder after creation of the content node.

    If you wanted to be able to edit the saved folder ID you could use the a Media Picker datatype (eventually only accepting folders).

    Now the folder has been created, and images can be added afterwards and will be automatically shown in front.

    I hope this make sense and fits your needs.

    /Søren

  • Tim Almond 8 posts 88 karma points
    Jan 24, 2018 @ 16:05
    Tim Almond
    0

    Hi Søren,

    Thanks for the reply.

    I didn't mean the folder Id, but the name. Now I think about it, the name of the main item we're editing would be good for a folder name. So, if we're editing an item with a name of "Odense", when we click on "+" to add an image, instead getting Media / + in the "Select Media dialog, we would have Media / Odense / + (after the mediaResource.addFolder had been called if necessary).

    I think I can do most of it - I was thinking of copying the MediaPickerController and at the start, adding the folder - I'm just not sure how to get the item name into my copy of the controller.

  • Søren Tidmand 118 posts 355 karma points
    Jan 25, 2018 @ 11:17
    Søren Tidmand
    100

    Hi Tim,

    This is exactly what happens if you do as suggested:

    • save the ID of the newly created media folder to a property on the content node (of type Media Picker)

    I just forgot to mention that you - in the first step of the action handler - need to save the media folder with the same name as the content node (that is initiating the action handler).

    Then the Media dialog of the content node will open up "inside" the selected media folder Media / Name of folder / + and the user can select images ... or images uploaded to this folder would automatically be shown if picking is not needed.

    Remember that the media folder name will not be accessible as physical folder on the server since all images are being saved individually in folders with an ID. The media folder name visible in the Media section (and Media Picker) is only saved in the database.

    If I'm not getting it right please correct me ;-)

    /Søren

  • Tim Almond 8 posts 88 karma points
    Feb 05, 2018 @ 12:19
    Tim Almond
    0

    Hi Søren,

    Thank you for your help.

    I went with a slightly different solution, where we dynamically generate a folder based on the node name, if it's not already present, and set umbLastOpenedMediaNodeId to the folder.

    I'm going to see if I can get the client to release the code. There's a few things this has got me thinking about with regards to the backoffice and images.

  • Søren Tidmand 118 posts 355 karma points
    Feb 05, 2018 @ 12:23
    Søren Tidmand
    0

    Hi Tim,

    Good that you found a solution that works. Would be interesting if your code could contribute to even better automatic workflows.

    /Søren

Please Sign in or register to post replies

Write your reply to:

Draft