A Shiny New Field Type: LinkList

[updated 2014-11-09]

According to reports and comments, this module is not compatible with Sitecore 7.2 (and up). The code is available on Github for anyone to grab a copy and fix the problem. If you do, please be kind and share the solution (or send me an email and I’ll update the code).

Here’s the project on Github.


 

It took long enough, but I finally finished a 1.0 version of the LinkList field type I was working on a while back. Unfortunately, somewhere along the way I lost the source code so I had to use ILSpy to get it back. ILSpy is a great tool for checking source code (I use it ALOT) but it doesn’t always generate pretty code as it is, in fact, IL code. Therefor, I will not publish the source code at this time (unless you really need it, then just email me or drop a comment here).

I wanted to handle links as content, not separate items, so I wanted to build a field type for it. Initially I wanted it to contain Sitecore.Data.Field.LinkField but was unable to find a way to populate it.

Without further ado; I give you Monoco LinkList Field Type as a Sitecore package.

Whats in the package?

  • The package contains the field definition item (installs under /sitecore/system/Field types/List Types in core db).
  • Files needed:
    • One tiny (well) DLL file in /bin
    • A config include (to inject the javascript file)
    • One javascript file for the content editor to respond to a few events needed.

Usage

Just create a new field on any template with the “Link List” field type and you’re set.

To access links, cast a field (LinkList field, that is) to Monoco.CMS.Fields.LinkList and go for the Links property, then bind it to a repeater or whatever you like.

What does it do?

It creates lists. Lists of links. Internal (Sitecore links), media (Sitecore media links, that is) and external

What does it look like?

I’ve included a screenshot;

Screenshot, ahem!

 

Disclaimer

Not claiming this is free from bugs but if you find any, feel free do drop me an email at code@monoco.se

Posted in Sitecore Tagged with: , ,
11 comments on “A Shiny New Field Type: LinkList
  1. skolima says:

    Not strictly on topic, but if you’re not happy with ILSpy decompiled code, then check out the results of JetBrains dotPeek (my preferred one currently) or Telerik JustDecompile. Or the trial version of Reflector. You’re much more likely to get feedback from others when you Sitecore module is on Shared Source.

    Yup, just repeating what was said on StackOverflow 😛

  2. Kenneth Kristensen says:

    Hi!
    I really this module and i have used it for other projects, but now i am working on a new project and it does not seem to work.
    The project i am working on is a Sitecore 7.2 (rev. 140526) and the issue i am facing is when i am trying to add Media and external links i get an error message like this:

    Handle not found.

    Stack trace:
    [InvalidOperationException: Handle not found.]
    Sitecore.Web.UrlHandle.Get(UrlString urlString, String handleName, Boolean removeSessionValue) +173
    Sitecore.Web.UrlHandle.Get(UrlString urlString, String handleName) +46
    Sitecore.Web.UrlHandle.Get(UrlString urlString) +47
    Sitecore.Web.UrlHandle.Get() +37
    Sitecore.Shell.Applications.Dialogs.LinkForm.GetLink() +10
    Sitecore.Shell.Applications.Dialogs.LinkForm.OnLoad(EventArgs e) +59
    Sitecore.Shell.Applications.Dialogs.MediaLink.MediaLinkForm.OnLoad(EventArgs e) +45

    Do you have an updated version of this module that will work in the new version of Sitecore?

    Thanks,
    Kenneth Kristensen

    • Andreas says:

      Hi Kenneth,

      I’ve heard others having problems with the 7.2 release of Sitecore. Unfortunately, I don’t work on Sitecore projects at the moment so I can’t really fix the problem. The code is available on Github, feel free to grab it and see if you can fix it: https://github.com/monoco/Monoco.CMS.FieldTypes (and please share the solution if you do).

      Andreas

  3. Gabor Maklari says:

    Hi!
    I’ve found the solution and made it compatible with Sitecore 7.2
    I will share it on github soon.

    • Jose says:

      Hey Gabor,

      Would you mind sharing your fix or quickly tell what you have to change to make it work on 7.2+

    • Lee says:

      Hi,

      Is it possible to share this solution? We are looking into using this module on a sitecore 7.2 solution soon and it would be good to have a fully working version.

  4. Pankaj Tiwari says:

    Did any one else have faced issues when If the link is too long, the buttons will move outside of the visible area and the user has to scroll to see them? Any solution found for this problem?

    We are using Sitecore 7.2 (rev. 140526).

    Thanks,
    Pankaj Tiwari

  5. Jose says:

    I’ve implemented a quick fix to make this works and seems to be working fine. I haven’t done much testing so I wouldn’t advise to use it on live environments without more testing.

    I changed the GetSelectText function a bit so it uses the Id of the internal and media links and displays the path of the item.

    private string GetSelectText(XmlNode node)
    {
    string attr = GetAttribute(node, “text”);
    var linkType = GetLinkType(node);

    string url = string.Empty;

    if (linkType.ToString().Equals(“internal”) || linkType.ToString().Equals(“media”))
    {
    string itemId = GetAttribute(node, “id”);
    if (!string.IsNullOrEmpty(itemId))
    {
    var item = Client.ContentDatabase.GetItem(new Sitecore.Data.ID(itemId));
    if (item != null)
    url = item.Paths.ContentPath;
    }
    }
    else
    {
    var urlObj = GetLinkUrl(node);
    if (urlObj != null)
    url = urlObj.ToString();
    }
    return string.Format(“{0} ({1}: {2})”, attr, linkType, url);
    }

    I had to make changes to EditLink and InsertLink function but to be honest I’m not 100% sure of this fix and some things might not be neccessary.. I did quick search with IlSpy to see how Sitecore is doing this and came up with this solution.

    Look for function InsertLink, look inside the else, where comment // Show the dialog using ShowModalDialog (line 163 in original file) and replace with
    // Show the dialog using ShowModalDialog.
    var urlString = new UrlString(args.Parameters[“url”]);

    UrlHandle urlHandle = new UrlHandle();
    urlHandle[“ro”] = Source;
    urlHandle[“db”] = Client.ContentDatabase.Name;
    urlHandle[“va”] = this.XmlValue.ToString();
    urlHandle.Add(urlString);

    urlString.Append(“sc_content”, WebUtil.GetQueryString(“sc_content”));
    Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog(urlString.ToString(), true);
    args.WaitForPostBack();

    Likewise on EditLink function. Look inside the else, where comment // Show the dialog using ShowModalDialog (line 112 in original file) and replace with
    // Show the dialog using ShowModalDialog.
    var urlString = new UrlString(args.Parameters[“url”]);

    UrlHandle urlHandle = new UrlHandle();
    urlHandle[“ro”] = Source;
    urlHandle[“db”] = Client.ContentDatabase.Name;
    urlHandle[“va”] = node.OuterXml;// this.XmlValue.ToString();
    urlHandle.Add(urlString);

    urlString.Append(“sc_content”, WebUtil.GetQueryString(“sc_content”));
    Sitecore.Context.ClientPage.ClientResponse.ShowModalDialog(urlString.ToString(), true);
    args.WaitForPostBack();

  6. shindai says:

    Could you please share your solution?
    @Gabor

  7. Marko says:

    I’ve committed a fix for 7.2, see https://github.com/MichaelHorsch/Monoco.CMS.FieldTypes/pull/1 for the code.

    This is a pull request on the MichaelHorsch fork as that fork has already done most of the heavy lifting for updating to 7.

2 Pings/Trackbacks for "A Shiny New Field Type: LinkList"
  1. […] The module was contributed by Andreas Bergström who blogged about the module here. […]

  2. […] The module was contributed by Andreas Bergström who blogged about the module here. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>