How to max an image picker where I limit the image...
# help-with-umbraco
m
I need to make a picker to give my editors the option to chosoe between the "Gold", "Silver", "Bronze", and "Platnium" medial images. I want to make it so they can't upload new images and have to pick one of those options. Is this a possible, and kind of easy, to do?
m
can you create a new mediaType, add your three as that new type, then remove permissions to allow adding anymore and use MNTP to limit the selection to that type and only 1? Maybe also have a companion newMediaTypeFolder for targetting MNTP to a start point in the tree?
m
MNTP? What media type would I be cloning? Just the image picker?
m
not a data type.. add a new media type 🙂 and use the multinodetreepicker datattype for your picker
same as you create document types, you can create you own media types (maybe as simple as copying image core mediatype but depends on what format you B/S/G are as could well be SVGs?)
and your MNTP can only allow that mediatype to be chosen (allow items of type) and min and max limits to one and mandatory one...
looks like media node type means you can't target a starting folder though..
Just a thought.. would a mandatory dropdownlist of B/S/G accomplish the same thing (with some additional coding to fetch a media item by key depending on the option chosen)... I know your users don't see an image in the back office... but is it really necessary?
m
I was thinking a radio select or dropdown but I don't know how to write the code on the template side to rended the right media image for the selected item. I mean, yes, a simple case statment but how do I point to the right media item since foldernames are randomized and how would I deal if the image is later replaced?
m
Off the top of my head
var mediaUrl = Umbraco.Media(new Guid("e3b091e7-77ad-46bc-9a3b-d46f70a4c83b")).MediaUrl();
though you might want to use GetCropUrl() too for responsive bitmap images.
the guid will not change when changing the image source.. and USync will persist guids between environments.
or an appsetting for your b/s/g guids? for environmental differences prod/uat/dev
c
TBH, it sounds like a custom picker or a Contentment pickers might be better than using a media picker? Does your client need to upload the images? If not, this might be better. This is the contentment docs: https://github.com/leekelleher/umbraco-contentment?tab=readme-ov-file
Depending on which version of Umbraco you are using, you might need to look up a different version of the docs, but here is a link to the Umbraco 13 docs that show you how to create a custom Property Editor / Data type. https://docs.umbraco.com/umbraco-cms/tutorials/creating-a-property-editor
m
Unfortunatlly I am not skilled enough to make a custom property and after looking at the Contentment it looks like it would work if I was just not using images.
c
Hi Matthew, it might be to complicated for you if you don't know how to code JS / C#, however Paul Seal wrote a good blog post that shows you how you can extend the contentment data list with your own picker interface ( he displays image thumbnails of authors ) https://skrift.io/issues/creating-an-author-picker-using-contentment/
m
Thanks I will take a look at that. I can do C# but I have not touched JS in like 20 years and know nothing about Angular. I would love to learn but it is a call between delaying a major project for an unknown amount of time while I learn or hobble something together that works but is not pritty. I may just direct upload the images I need to use and hardcode a path. I don't see the images changing ever but maybe one day I can afford to pay a pro to fix my bad code 😛
c
@Matthew Alexandros - A combination of ChatGPT & Copilot and reading though the links I just sent you would probably get you 98% of the way there 🙂
m
I have been thinking on this more and I have decided to push my deadline out from Jun 1 to Jan 1 so I can take time to go over this stuff and other things I had to just Hank together so I can properly do it. Also going to tao into my retirement savings so I can also hire professionals to tackle some of these things as well. Thanks for your help and suggestions.
2 Views