Copied to clipboard

Flag this post as spam?

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


  • Jamie Bryant 3 posts 84 karma points
    Jun 21, 2019 @ 13:45
    Jamie Bryant
    0

    trying to add a new provider for embed on the rich text editor

    Hi i am trying to add a new provider for embed on the rich text editor, every where ive looked online is saying add it to embeddedmedia.config but i dont seem to have this file! Im using v8 if anyone could shed some light that would be great. Also how do i use ifame in umbraco v8?

    Thank you

  • Marc Goodson 1290 posts 8721 karma points MVP 5x c-trib
    Jun 23, 2019 @ 09:22
    Marc Goodson
    2

    Hi Jamie

    It's the same theory as in V7, except in V8 'a lot' of the configuration has moved from configuration files into code.

    So for example if you wanted to create a new Embed provider for the DeviantArt website (like in the v7 documentation).. you'd create a provider like so:

    using System.Collections.Generic;
    using Umbraco.Web.Media.EmbedProviders;
    
    namespace umbraco8.EmbedProviders
    {
        public class DeviantArtEmbedProvider : EmbedProviderBase
        {
            public override string ApiEndpoint => "https://backend.deviantart.com/oembed?url=";
    
            public override string[] UrlSchemeRegex => new string[]
            {
                @"fav\.me/*"
            };
    
            public override Dictionary<string, string> RequestParams => new Dictionary<string, string>();
    
            public override string GetMarkup(string url, int maxWidth = 0, int maxHeight = 0)
            {
                var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight);
                var oembed = base.GetJsonResponse<OEmbedResponse>(requestUrl);
    
                return oembed.GetHtml();
            }
        }
    }
    

    This replaces what you would have added to the embeddedmedia.config file.

    And then there is a further step to let Umbraco know about the provider, add a new class to your project inheriting 'IUserComposer' and we can use the OEmbedProviders extension method to add the new provider in eg:

    using Umbraco.Core.Composing;
    using Umbraco.Web;
    using umbraco8.EmbedProviders;
    
    namespace umbraco.Composing
    {
        public class RegisterEmbedProvidersComposer : IUserComposer
        {
            public void Compose(Composition composition) => composition.OEmbedProviders().Append<DeviantArtEmbedProvider>();
        }
    }
    

    regards

    Marc

  • Richard Hamilton 36 posts 157 karma points
    Jul 21, 2020 @ 11:19
    Richard Hamilton
    0

    I'm trying this but its not hitting RegisterEmbedProvidersComposer

Please Sign in or register to post replies

Write your reply to:

Draft