Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

How to convert block property types with MigrationSteps?

$
0
0

Hello everyone,

the question was already asked here:

https://world.episerver.com/forum/developer-forum/Developer-to-developer/Thread-Container/2018/2/how-to-update-old-page-type-property-values/

i actually want to do exactly the same, convert an existing string property in a page to XhtmlString. So i want to use MigrationSteps.

Unfortunately there is nowhere an example on how to do it. This is the documentation:

https://world.episerver.com/documentation/developer-guides/CMS/Content/Refactoring-content-type-classes/#changetype

It lacks sample code(apart from renaming a property which you find everywhere in the internet) that shows how to convert the type.

As a workaround i have tried to do it with another property even if that pollutes my class and needs a lot of work to fix it everywhere:

[CultureSpecific]
[Display(
	Name = "Title",
	Description = "Article title",
	Order = 999)]
[ScaffoldColumn(false)]
[Editable(false)]
[Obsolete("Replaced with the XhtmlString property ArticleTitle")]
public virtual string Title { get; set; }
[CultureSpecific]
[Display(
	Name = "Title",
	Description = "Article title",
	Order = 220)]
[UIHint(UIHint.Textarea)]
public virtual XhtmlString ArticleTitle
{
	get
	{
		XhtmlString articleTitle = this.GetPropertyValue(page => page.ArticleTitle);
		return articleTitle ?? new XhtmlString(this.GetPropertyValue(page => page.Title));
	}
	set { this.SetPropertyValue(page => page.ArticleTitle, value); }
}

One issue i have with this is that the old Title is correctly returned but it's not visible in CMS. So the CMS-Editor thinks it is empty. How to fix that?

Thanks in advance,

Tim


Viewing all articles
Browse latest Browse all 8020

Trending Articles