-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathMigrations.cs
151 lines (123 loc) · 5.76 KB
/
Migrations.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System.ComponentModel;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.Data.Migration;
namespace OrchardCore.Forms
{
public class Migrations : DataMigration
{
private readonly IContentDefinitionManager _contentDefinitionManager;
public Migrations(IContentDefinitionManager contentDefinitionManager)
{
_contentDefinitionManager = contentDefinitionManager;
}
public int Create()
{
// Form
_contentDefinitionManager.AlterPartDefinition("FormPart", part => part
.Attachable()
.WithDescription("Turns your content item into a form."));
_contentDefinitionManager.AlterTypeDefinition("Form", type => type
.WithPart("TitlePart", part => part
.WithSettings<TitlePartSettings>(new TitlePartSettings { RenderTitle = false })
.WithPosition("0")
)
.WithPart("FormElementPart", part =>
part.WithPosition("1")
)
.WithPart("FormPart")
.WithPart("FlowPart")
.Stereotype("Widget"));
// FormElement
_contentDefinitionManager.AlterPartDefinition("FormElementPart", part => part
.WithDescription("Provides attributes common to all form elements."));
// FormInputElement
_contentDefinitionManager.AlterPartDefinition("FormInputElementPart", part => part
.WithDescription("Provides attributes common to all input form elements."));
// Label
_contentDefinitionManager.AlterPartDefinition("LabelPart", part => part
.WithDescription("Provides label properties."));
_contentDefinitionManager.AlterTypeDefinition("Label", type => type
.WithPart("TitlePart", part => part
.WithSettings<TitlePartSettings>(new TitlePartSettings { RenderTitle = false })
)
.WithPart("FormElementPart")
.WithPart("LabelPart")
.Stereotype("Widget"));
// Input
_contentDefinitionManager.AlterPartDefinition("InputPart", part => part
.WithDescription("Provides input field properties."));
_contentDefinitionManager.AlterTypeDefinition("Input", type => type
.WithPart("FormInputElementPart")
.WithPart("FormElementPart")
.WithPart("InputPart")
.Stereotype("Widget"));
// TextArea
_contentDefinitionManager.AlterPartDefinition("TextAreaPart", part => part
.WithDescription("Provides text area properties."));
_contentDefinitionManager.AlterTypeDefinition("TextArea", type => type
.WithPart("FormInputElementPart")
.WithPart("FormElementPart")
.WithPart("TextAreaPart")
.Stereotype("Widget"));
// Select
_contentDefinitionManager.AlterPartDefinition("SelectPart", part => part
.WithDescription("Provides select field properties."));
_contentDefinitionManager.AlterTypeDefinition("Select", type => type
.WithPart("FormInputElementPart")
.WithPart("FormElementPart")
.WithPart("SelectPart")
.Stereotype("Widget"));
// Button
_contentDefinitionManager.AlterPartDefinition("ButtonPart", part => part
.WithDescription("Provides button properties."));
_contentDefinitionManager.AlterTypeDefinition("Button", type => type
.WithPart("FormInputElementPart")
.WithPart("FormElementPart")
.WithPart("ButtonPart")
.Stereotype("Widget"));
// Validation Summary
_contentDefinitionManager.AlterPartDefinition("ValidationSummaryPart", part => part
.WithDescription("Displays a validation summary."));
_contentDefinitionManager.AlterTypeDefinition("ValidationSummary", type => type
.WithPart("ValidationSummaryPart")
.Stereotype("Widget"));
// Validation
_contentDefinitionManager.AlterPartDefinition("ValidationPart", part => part
.WithDescription("Displays a field validation error."));
_contentDefinitionManager.AlterTypeDefinition("Validation", type => type
.WithPart("ValidationPart")
.Stereotype("Widget"));
return 3;
}
public int UpdateFrom1()
{
_contentDefinitionManager.AlterTypeDefinition("Form", type => type
.WithPart("TitlePart", part => part.MergeSettings<TitlePartSettings>(setting => setting.RenderTitle = false))
);
_contentDefinitionManager.AlterTypeDefinition("Label", type => type
.WithPart("TitlePart", part => part.MergeSettings<TitlePartSettings>(setting => setting.RenderTitle = false))
);
return 2;
}
public int UpdateFrom2()
{
_contentDefinitionManager.AlterTypeDefinition("Form", type => type
.WithPart("TitlePart", part => part
.WithPosition("0")
)
.WithPart("FormElementPart", part =>
part.WithPosition("1")
)
);
return 3;
}
internal class TitlePartSettings
{
public int Options { get; set; }
public string Pattern { get; set; }
[DefaultValue(true)]
public bool RenderTitle { get; set; }
}
}
}