Try our conversational search powered by Generative AI!

Overriding default MediaRepositoryDescriptor in Edit mode.


Hello forum,

We are in situation where we need to override the default MediaRepositoryDescriptor with our own implementation in order to organize our multisite media folders in a more structured manner.  Basically we are getting almost everything working as we would like by simply declaring our repositorydescriptor:

    public class MyMediaRepositoryDescriptor : MediaRepositoryDescriptor, IContentRepositoryDescriptor
        public static string RepositoryKey { get { return "images"; } }

        public override string Key { get { return RepositoryKey; } }

        public override IEnumerable<ContentReference> Roots {
            get {
                //return our customized root folders

 And then utilizing the repo descriptor with custom editor descriptors for images and media, like this:

    [EditorDescriptorRegistration(TargetType = typeof(ContentReference), UIHint = "image", EditorDescriptorBehavior = EditorDescriptorBehavior.OverrideDefault)]
    public class MyImageReferenceEditorDescriptor: ImageReferenceEditorDescriptor
        private readonly IContentRepositoryDescriptor _myMediaRepositoryDescriptor;

        public MyImageReferenceEditorDescriptor() : this(ServiceLocator.Current.GetInstance<FileExtensionsResolver>(), ServiceLocator.Current.GetInstance<IContentRepositoryDescriptor>())

        public MyImageReferenceEditorDescriptor(FileExtensionsResolver fileExtensionsResolver, IContentRepositoryDescriptor contentRepositoryDescriptor) : base(fileExtensionsResolver)
            _myMediaRepositoryDescriptor = contentRepositoryDescriptor;
        public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)

            base.ModifyMetadata(metadata, attributes);
            //metadata.EditorConfiguration["allowedExtensions"] = _fileExtensionsResolver.GetAllowedExtensions(typeof(IContentImage), metadata.Attributes.OfType<Attribute>());
            metadata.EditorConfiguration["roots"] = _myMediaRepositoryDescriptor.Roots;

        public override string RepositoryKey => _myMediaRepositoryDescriptor.Key;

 In similar manner we have created overrides for default ImageUrlEditorDescriptor and of course medias as well with the help of ILSpy.

The editordescriptors work for most cases just fine: we can create content references with image UIHint and all that. Only place where this approach does not work is TInyMce Insert/edit image functionality:

Where I am only ever able to see the near standard root folders and not the hierarchy from my custom repository.

Is there anyone who knows where the roots for that widgets are set/can be changed? I've spent considerable amount of time looking at widget code but am no wiser than when I started. Any help would be much appreciated!

Jun 29, 2023 12:56

Unfortunately, with the current implementation of the built-in Insert/edit image plugin, it's impossible to change the roots.

The media selector in the Insert/edit image plugin only works with MediaRepositoryDescriptor where RepositoryKey is "media".

In your case, if you only need to update the Roots, I would suggest you update your MyMediaRepositoryDescriptor.RepositoryKey to media and remove the original MediaRepositoryDescriptor by adding the following line after ".AddCms()" in your Startup.cs

services.Remove(services.Single(s => s.ImplementationType == typeof(Cms.Shell.UI.UIDescriptors.MediaRepositoryDescriptor)));
Jul 03, 2023 6:58
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.