Skip to content

Commit f072cd6

Browse files
authored
Merge pull request #388 from Kentico/docs/pages-to-widgets
DOCS: Migrate pages to widgets
2 parents 8522c34 + 7c4871e commit f072cd6

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Migration.Tool.CLI/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ Pages from older product versions can be migrated to either to [website channel
168168
- Page permissions (ACLs) are currently not migrated into Xperience by Kentico.
169169
- Migration of page builder content is only available for Kentico Xperience 13.
170170

171+
Additionally, you can define [custom migrations](../Migration.Tool.Extensions/README.md) to change the default behavior and migrate page content to widgets in Xperience by Kentico.
172+
171173
#### Page builder content
172174

173175
> :warning: Page builder content migration is only available when migrating from Kentico Xperience 13.

Migration.Tool.Extensions/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ To create custom migrations:
66
- [Field migrations](#customize-field-migrations)
77
- [Widget migrations](#customize-widget-migrations)
88
- [Widget property migrations](#customize-widget-property-migrations)
9+
- [Page to widget migrations](#migrate-pages-to-widgets)
910
- [Custom class mappings](#custom-class-mappings)
1011
2. [Register the migration](#register-migrations)
1112

@@ -70,13 +71,77 @@ You can see samples:
7071

7172
After implementing the migration, you need to [register the migration](#register-migrations) in the system.
7273

74+
## Migrate pages to widgets
75+
76+
This migration allows you to migrate pages from the source instance as [widgets](https://docs.kentico.com/x/7gWiCQ) in the target instance. This migration can be used in the following ways:
77+
78+
- If you have a page with content stored in page fields, you can migrate the values of the fields into widget properties and display the content as a widget.
79+
- If you have a page that serves as a listing and displays content from child pages, you can convert the child pages into widgets and as content items in the content hub, then link them from the widgets.
80+
81+
> :warning: The target page (with a [Page Builder editable area](https://docs.kentico.com/x/7AWiCQ)) and any [Page Builder components](https://docs.kentico.com/x/6QWiCQ) used in the migration need to be present in the system before you migrate content. The target page must be either the page itself or any ancestor of the page from which the content is migrated.
82+
83+
In `Migration.Tool.Extensions/CommunityMigrations`, create a new file with a class that inherits from the `ContentItemDirectorBase` class and override the `Direct(source, options)` method:
84+
85+
1. If the target page uses a [page template](https://docs.kentico.com/x/iInWCQ), ensure that the correct page template is applied.
86+
87+
```csharp
88+
// Store page uses a template and is the parent listing page
89+
if (source.SourceNode.SourceClassName == "Acme.Store")
90+
{
91+
// Ensures the page template is present in the system
92+
options.OverridePageTemplate("StorePageTemplate");
93+
}
94+
```
95+
96+
2. Identify pages you want to migrate to widgets and use the `options.AsWidget()` action.
97+
98+
```csharp
99+
// Identifies pages by their content type
100+
else if (source.SourceNode.SourceClassName == "Acme.Coffee")
101+
{
102+
options.AsWidget("Acme.CoffeeSampleWidget", null, null, options =>
103+
{
104+
// Determines where to place the widget
105+
options.Location
106+
// Negative indexing is used - '-1' signifies direct parent node
107+
// Use the value of '0' if you want to target the page itself
108+
.OnAncestorPage(-1)
109+
.InEditableArea("main-area")
110+
.InSection("SingleColumnSection")
111+
.InFirstZone();
112+
113+
// Specifies the widget's properties
114+
options.Properties.Fill(true, (itemProps, reusableItemGuid, childGuids) =>
115+
{
116+
// Simple way to achieve basic conversion of all properties, properties can be refined in the following steps
117+
var widgetProps = JObject.FromObject(itemProps);
118+
119+
// The converted page is linked as a reusable content item into a single property of the widget.
120+
// NOTE: List the page class name app settings in ConvertClassesToContentHub to make it reusable!
121+
widgetProps["LinkedContent"] = LinkedItemPropertyValue(reusableItemGuid!.Value);
122+
123+
// Link reusable content items created from page's original subnodes
124+
// NOTE: List the page class names in app settings in ConvertClassesToContentHub to make it reusable!
125+
widgetProps["LinkedChildren"] = LinkedItemsPropertyValue(childGuids);
126+
127+
return widgetProps;
128+
});
129+
});
130+
}
131+
```
132+
133+
You can see a sample: [SamplePageToWidgetDirector.cs](./CommunityMigrations/SamplePageToWidgetDirector.cs)
134+
135+
After implementing the content item director, you need to [register the director](#register-migrations) in the system.
136+
73137
## Register migrations
74138

75139
Register the migration in `Migration.Tool.Extensions/ServiceCollectionExtensions.csas a `Transientdependency into the service collection:
76140

77141
- Field migrations - `services.AddTransient<IFieldMigration, MyFieldMigration>();`
78142
- Widget migrations - `services.AddTransient<IWidgetMigration, MyWidgetMigration>();`
79143
- Widget property migrations - `services.AddTransient<IWidgetPropertyMigration, MyWidgetPropertyMigration>();`
144+
- Page to widget migrations - `services.AddTransient<ContentItemDirectorBase, MyPageToWidgetDirector>();`
80145

81146
## Custom class mappings
82147

0 commit comments

Comments
 (0)