Try our conversational search powered by Generative AI!

Is it possible to modify the Create Link modal?

Ian
Ian
Vote:
 

I'm looking to support additional attributes that should get rendered by any existing Url field. Given how much CMS content already exists, I would rather not have to create a custom block to achieve this, but would love to modify this window directly. Specifically, I have several data- attributes related to click tracking I'd like to be able to give editors the option to manage on a per-link field basis.

Is that possible? Recommended, even? Thanks in advance...

#270286
Edited, Jan 20, 2022 21:20
Vote:
 
#270329
Jan 21, 2022 12:01
Ian
Vote:
 

Thanks Scott -- I did see this and gave it a shot, but I ran into the same issues others in the comments did and can't get the modal to render with the supplied code since it's based on earlier version of the CMS. 

#270333
Jan 21, 2022 14:40
Vote:
 

Hey Ian, I've just posted a new version of that code on my blog, which works for version 11 of the CMS. It should work for version 12 too but I haven't test it yet. 

https://ynze.hashnode.dev/extending-the-hyperlink-editor-in-version-11

#272633
Edited, Feb 21, 2022 3:24
Ian
Vote:
 

Thanks Ynze, this is great! 

#275907
Mar 08, 2022 14:12
Vote:
 

Hi Ian,

Did you start implementing this? I'd imagine itcould get a little tricky for a few reasons (and depending on your precise needs):

  1. You'd likely have to do some heavy Dojo customisation, depending on how you wanted editors to be able to enable data attributes
  2. The URL property is backed by a string, so you'd have to persist everything as a single string in the database
  3. You'd need to split the URL property above when rendering to extract the data attributes out

I also did a blog about customising this, specifically covering adding a telephone link option: https://jakejon.es/blog/adding-a-telephone-link-option-to-the-episerver-link-editor

I'd probably advise against doing this, but if you're already started I'd really like to hear what your approach is 😊

#275911
Mar 08, 2022 17:08
Ian
Vote:
 

Hi Jake--

I have, but I've found another route that doesn't involve any Dojo customization. Essentially, I wanted to allow editors to select specific types of blocks (any inheriting `IModalContentBlock`) as a link, instead of a page. In order to do so, I needed to create a new class inheriting from `ContentRepositoryDescriptorBase`. From there, I created a custom UrlResolver class to render the links appropriately. Here is the full class below that adds the extra field I was after to the create link dialog window:

[ServiceConfiguration(typeof(IContentRepositoryDescriptor))]
public class ModalContentContentPickerDescriptor : ContentRepositoryDescriptorBase
{
    public IEnumerable<Type> ModelTypes
    {
        get
        {
            return typeof(IModalContentBlock).Assembly.GetTypes()
                .Where(x =>
                    typeof(IModalContentBlock).IsAssignableFrom(x)
                    && !x.IsInterface
                    && !x.IsAbstract).ToArray();
        }
    }

    public static string RepositoryKey => "modalContentRepo";

    public override string Key => RepositoryKey;

    public override string Name => "Modal Content";

    public override IEnumerable<Type> LinkableTypes => ModelTypes;

    public override IEnumerable<Type> ContainedTypes
    {
        get
        {
            var types = ModelTypes.ToList();

            types.AddRange(new[]
            {
                typeof(ContentFolder),
            });

            return types;
        }
    }

    public override IEnumerable<Type> CreatableTypes => ModelTypes;

    public override string SearchArea => "cms/blocks";

    public override IEnumerable<ContentReference> Roots =>
        new List<ContentReference>
        {
            ContentReference.SiteBlockFolder,
            ContentReference.GlobalBlockFolder,
        };

    public override IEnumerable<Type> MainNavigationTypes
    {
        get
        {
            return new[]
            {
                typeof(ContentFolder)
            };
        }
    }
}
#277081
Mar 24, 2022 15:48
* 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.