Consider extracting media picker as view component
Is your feature request related to a problem?
I had a few cases where I needed to use the media picker component in my custom module, but without using or relying on the MediaField, which heavily depends on ContentField. In my custom ViewModel I would like to have just simple child ViewModel represents media and a ViewComponent that is responsible for displaying it.
Describe the solution you'd like
In my solution, I extracted much of the existing code from the MediaField view and placed it into a custom view component, allowing the media picker functionality to be used in a more flexible way that fits my use cases. The main idea is to separate the media picker (as a view component) from the MediaField, so that the MediaField view would use the view component instead of embedding the media picker directly. Are there any drawbacks to this approach?
Describe alternatives you've considered
The alternative is to create and maintain such view components by users, which is a bit annoying, as a lot of code has to be duplicated from MediaField View and then tracked to keep up with future changes.
Can you explain the use-case a bit more? What was the feature you created where you wanted to use the Media picker without the field? This is so we can understand better what kind of solution would be appropriate.
So, this idea originated as a result of this discussion: https://github.com/OrchardCMS/OrchardCore/discussions/18014 I had some custom module with admin settings for which one of the fields was icon admin user is allow to select. Because settings are part of ISite which is low entity than content item I was not able to use MediaField that derives from ContentField and require parent ContentItem. Suggestion was to use Custom Settings that is backed by ContentItem but I didn't want to go this route because I wanted to have more control on how my settings are rendered in admin menu. Finally I realised I can extract entire view from MediaField.Edit.cshtml into ViewComponent and use it to render my small ViewModel for Icon/Image settings without need for ContentField. This improves reusability of media selector/picker component outside ContentField concept.
We need to start creating ES6 modules so that these components be reusable. As you can see OC is mostly made of CommonJS scripts. The idea is great.
I see, thanks for explaining.
FWIW, you have complete control over how Custom Settings are rendered, since all of that can be overridden, just as for every content item.
We triaged this issue and set the milestone according to the priority we think is appropriate (see the docs on how we triage and prioritize issues).
This indicates when the core team may start working on it. However, if you'd like to contribute, we'd warmly welcome you to do that anytime. See our guide on contributions here.