LinkItemCollection- Set default/optional for Link name/text

Vote:
 

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

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

Hi Eric Herlitz 

 I am using cms version 12.17.0 with dotnet 6

Thank you

Binay Thakur

#297125
Feb 24, 2023 5:44
Vote:
 

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

[Display(
    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. 

[Display(
    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

[Display(
    GroupName = SystemTabNames.Content,
    Order = 30)]
[JsonProperty]
[JsonConverter(typeof(UrlConverter))]
[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; }
}

[PropertyDefinitionTypePlugIn]
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 https://world.optimizely.com/forum/developer-forum/CMS/Thread-Container/2019/6/url-property-disappear-when-adding-and-publishing/

#297131
Edited, Feb 24, 2023 11:18
Vote:
 

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.

{
                "href""https://localhost:5000/en/start-page/custompage",
                "title"null,
                "target"null,
                "text""Internal Link",
                "contentLink": {
                    "id"179,
                    "workId"0,
                    "guidValue""00db5659-72ee-4d43-9077-0e27f3c2d82d",
                    "providerName"null,
                    "url":  "https://localhost:5000/en/start-page/custompage",
                    "expanded"null
 }
#297132
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.