Try our conversational search powered by Generative AI!

Bartosz Sekula
Sep 14, 2022
  3076
(4 votes)

Built-in support for single LinkItem property

EPiServer.CMS 12.11.0 introduces a new property type LinkItem . This feature has been one of the most requested features for a long time.

The feature is very simple: it is to allow the editor to choose a single LinkItem. 

After clicking the `Add Link` button editor is presented with the standard Linkitem dialog:

After selecting any content item the editor will look like this:

In order to use the new property type you just need to use the LinkItem data type. No annotations are needed.

public class PartnerPage : PageData
{
    public virtual LinkItem MyLink { get; set; }
}

Migration from EPiServer.Labs.LinkItemProperty

If you used the Labs package before and you wish to update then you will need to follow a few manual upgrade steps:

Labs used the following:

public class PartnerPage : PageData
{
    [LinkItemProperty]
    [BackingType(typeof(PropertyLinkCollection))]
    public virtual LinkItem Link
    {
        get => this.GetLinkItemPropertyValue(nameof(Link));
        set => this.SetLinkItemPropertyValue(nameof(Link), value);
    }
}

You have to remove both LinkItemProperty and BackingType annotations and switch to auto property.

public class PartnerPage : PageData
{
    public virtual LinkItem Link { get; set; }
}

You will also need to run the following SQL command (don't forget to do the backup for safety)

DECLARE @PropertiesToUpdate NVARCHAR(4000); -- one or more coma separated properties to update with [ContentTypeName.PropertyName] format
SET @PropertiesToUpdate = ''; -- for example ArticlePage2.SingleLink,ArticlePage2.SingleLinkCultureSpecific

-- update published versions
UPDATE tblContentProperty
 SET tblContentProperty.LongString = SUBSTRING(  -- start after `<links>`
           SUBSTRING(propValue.LongString, 0, CHARINDEX('</a>',  propValue.LongString) + 4), -- remove all text after first `</a>`
           8, 100000)
 OUTPUT INSERTED.*, deleted.*
  FROM tblPropertyDefinition propDef
  JOIN tblPropertyDefinitionType propDefType ON propDefType.[Name] = 'LinkCollection'
   AND propDef.fkPropertyDefinitionTypeID = propDefType.pkID
  JOIN tblContentType ON tblContentType.pkID = propDef.fkContentTypeID
  JOIN tblContentProperty propValue ON propValue.fkPropertyDefinitionID = propDef.pkID
 WHERE propValue.LongString LIKE '<links>%'
   AND CHARINDEX(tblContentType.[Name] + '.' + propDef.[Name] + ',', @PropertiesToUpdate + ',') > 0;

-- update versions  
UPDATE tblWorkContentProperty
   SET tblWorkContentProperty.LongString = SUBSTRING(  -- start after `<links>`
          SUBSTRING(propValue.LongString, 0, CHARINDEX('</a>',  propValue.LongString) + 4), -- remove all text after first `</a>`
          8, 100000)
OUTPUT INSERTED.*, deleted.*
  FROM tblPropertyDefinition propDef
  JOIN tblPropertyDefinitionType propDefType ON propDefType.[Name] = 'LinkCollection'
   AND propDef.fkPropertyDefinitionTypeID = propDefType.pkID
  JOIN tblContentType ON tblContentType.pkID = propDef.fkContentTypeID
  JOIN tblWorkContentProperty propValue ON propValue.fkPropertyDefinitionID = propDef.pkID
 WHERE propValue.LongString LIKE '<links>%'
   AND CHARINDEX(tblContentType.[Name] + '.' + propDef.[Name] + ',', @PropertiesToUpdate + ',') > 0;

-- update property type
UPDATE tblPropertyDefinition
   SET tblPropertyDefinition.fkPropertyDefinitionTypeID = (SELECT pkID from tblPropertyDefinitionType where [Name] = 'LinkItem')
OUTPUT INSERTED.*, deleted.*
  FROM tblContentType
 WHERE tblPropertyDefinition.fkPropertyDefinitionTypeID = (SELECT pkID from tblPropertyDefinitionType where [Name] = 'LinkCollection') 
   AND CHARINDEX(tblContentType.[Name] + '.' + tblPropertyDefinition.[Name] + ',', @PropertiesToUpdate + ',') > 0;

Afterwards the Labs package can just be uninstalled.

Sep 14, 2022

Comments

Please login to comment.
Latest blogs
Anonymous Tracking Across Devices with Optimizely ODP

An article by Lead Integration Developer, Daniel Copping In this article, I’ll describe how you can use the Optimizely Data Platform (ODP) to...

Daniel Copping | Apr 30, 2024 | Syndicated blog

Optimizely Forms - How to add extra data automatically into submission

Some words about Optimizely Forms Optimizely Forms is a built-in add-on by Optimizely development team that enables to create forms dynamically via...

Binh Nguyen Thi | Apr 29, 2024

Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024