LinkItemCollection- Set default/optional for Link name/text


Hello Team,

     I am using LinkItemCollection property into the page. When I am creating a new link, system is forcing me to add the  Link name/text field value. Can we set the default value or make it this field optional  ?

Thanks & Regards

Binay Thakur

Edited, Feb 23, 2023 12:28
Eric Herlitz - Feb 23, 2023 14:06
Which version of CMS are you running?

Hi Eric Herlitz 

 I am using cms version 12.17.0 with dotnet 6

Thank you

Binay Thakur

Feb 24, 2023 5:44

The name/text field comes from the LinkItem object where it is required.

An alternative to the LinkItemCollection is to create your own link list which can be done in a few different ways, the ideal solution would probably be using the Episerver.Url object. The Url object unfortunately lack a constructorless parameter so it is not usable in a IList property just yet, but it may be improved in 12.18. 

That implementation would in that case look like this

    GroupName = SystemTabNames.Content,
    Order = 30)]
public virtual IList<Url> UrlList { get; set; }

Since we dont have that just yet, are you planning to link only internal pages and resources you'll probably find using a ContentReference list the easiest to implement, e.g. 

    GroupName = SystemTabNames.Content,
    Order = 30)]
public virtual IList<ContentReference> ContentReferences { get; set; }

If you still want to use the Url property but create a custom propertylist something like this may suffice

    GroupName = SystemTabNames.Content,
    Order = 30)]
[EditorDescriptor(EditorDescriptorType = typeof(CollectionEditorDescriptor<Link>))]
public virtual IList<Link> Urls { get; set; }

Where Link would be a property list looking something like this

public class Link
    [Display(Name = "Title", Description = "", GroupName = SystemTabNames.Content, Order = 1)]
    public virtual string NonRequiredTitle { get; set; }

    [Display(Name = "Link", Description = "", GroupName = SystemTabNames.Content, Order = 2)]
    public virtual Url LinkTo { get; set; }

public class LinksProperty : PropertyList<Link> { }

I didn't really test the PropertyList<Link> solution with CMS 12 and it is heavily inspired by this solution

Edited, Feb 24, 2023 11:18

Eric Herlitz Thank you for response.

I am agree with your alternate solution. But our requirement is to set any url that can be either internal or external. I am using LinkItemCollection becuase this property returns external url and internal page details both. But url property desn't return internal page detail. So I believe you alternate solution will not work for me

Here is LinkItemCollection property api response.

                "text""Internal Link",
                "contentLink": {
                    "url":  "https://localhost:5000/en/start-page/custompage",
Edited, Feb 24, 2023 11:43
* 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.