From the way that the issue is described in your post, the actual links that you are trying to intercept are a bit ambiguous. If your links are all from link fields, then the answer is very different from what it would be if you are trying to intercept all links on the site. If your links are all in link fields, I implore you to read the first section. If that isn't the case with your solution, then - recognizing that the first section still had to be said - read onto the second section.
If your links are all coming from Link fields...
If your links are all coming from Link fields, then I think that you may be thinking too much about the HTML that you are planning to render and not enough about the data. It's something that I feel like every developer, myself included, goes through when learning a CMS. If you separate the data from the rendered markup in your mind, it doesn't matter whether you use an anchor tag to pop up your modal or a span.
If all of the links that you are referring to are link fields, then you can accomplish what you are looking for with a droplink that points to a footnote item that holds the data you plan to render in your attributes.
If your links are coming (or may come) from the RTE...
In order to intercept the way that Sitecore expands links inside of the RTE, you will need to create a custom LinkProvider
that uses a custom LinkParser
. You will need to override the LinkProvider.CreateLinkParser
method to return your custom LinkParser
type, and you will need to make your LinkParser
return a custom LinkExpander
that will handle the "footnote links."
To start, you will need to implement your new FootnoteSupportingLinkParser
, like so:
public class FootnoteSupportingLinkParser : LinkProvider.LinkParser
{
public override IEnumerable<LinkExpander> GetExpanders()
{
return (IEnumerable<LinkExpander>) new Collection<LinkExpander>()
{
(LinkExpander) new MediaLinkExpander(),
(LinkExpander) new FootnoteSupportingItemLinkExpander()
};
}
}
Note that the type FootnoteSupportingItemLinkExpander
does not actually exist. The idea, here, is to create your own implementation of the Sitecore.Links.ItemLinkExpander
that will expand links to footnote items one way and links to other items the default way. You can do this like so:
public class FootnoteSupportingItemLinkExpander : ItemLinkExpander
{
public override void Expand(ref string text, UrlOptions urlOptions)
{
Assert.ArgumentNotNull((object) text, "text");
Assert.ArgumentNotNull((object) urlOptions, "urlOptions");
int startIndex1 = text.IndexOf("~/link.aspx?", StringComparison.InvariantCulture);
if (startIndex1 == -1)
return;
StringBuilder stringBuilder = new StringBuilder(text.Length);
int startIndex2 = 0;
for (; startIndex1 >= 0; startIndex1 = text.IndexOf("~/link.aspx?", startIndex2, StringComparison.InvariantCulture))
{
int num = text.IndexOf("_z=z", startIndex1, StringComparison.InvariantCulture);
if (num < 0)
{
text = stringBuilder.ToString();
return;
}
// TODO: change this to resolve target item (or null)
string url = DynamicLink.Parse(text.Substring(startIndex1, num - startIndex1)).GetUrl(urlOptions);
// TODO: write in logic to check if target item is a footnote item
// TODO: if a footnote item, change the following to parse the footnote link as desired
string str = text.Substring(startIndex2, startIndex1 - startIndex2);
stringBuilder.Append(str);
stringBuilder.Append(url);
startIndex2 = num + "_z=z".Length;
}
stringBuilder.Append(text.Substring(startIndex2));
text = stringBuilder.ToString();
}
}
Next, you will need to implement your new FootnoteSupportingLinkProvider
, like so:
public class FootnoteSupportingLinkProvider : LinkProvider
{
protected override LinkProvider.LinkParser CreateLinkParser()
{
return new FootnoteSupportingLinkParser();
}
}
Lastly, you will need to register your new FootnoteSupportingLinkProvider
type, which you can do with the following patch:
<linkManager>
<patch:attribute name="defaultProvider" value="footnoteSupportingProvider" />
<providers>
<add name="footnoteSupportingProvider" type="MyProject.MyNamespace.FootnoteSupportingLinkProvider, MyProject" />
</providers>
</linkManager>