私のモジュールは、コントローラを介してカスタムコンテンツアイテムを作成します。フィールドインデックスは、プログラム
はprivate ContentItem createContentItem()
{
// Add the field
_contentDefinitionManager.AlterPartDefinition(
"TestType",
cfg => cfg
.WithField(
"NewField",
f => f
.OfType(typeof(BooleanField).Name)
.WithDisplayName("New Field"))
);
// Not sure if this is needed
_contentDefinitionManager.AlterTypeDefinition(
"TestType",
cfg => cfg
.WithPart("TestType")
);
// Create new TestType item
var newItem = _contentManager.New("TestType");
_contentManager.Create(TestItem, VersionOptions.Published);
// Set the added boolean field to true
BooleanField newField = ((dynamic)newItem).TestType.NewField as BooleanField;
newField.Value = true;
// Set title (as date created, for convenience)
var time = DateTime.Now.ToString("MM-dd-yyyy h:mm:ss tt", CultureInfo.InvariantCulture).Replace(':', '.');
newItem.As<TitlePart>().Title = time;
return newItem;
}
これの最終結果がtrueに設定されていますフィールドを持つ新しいをTestTypeアイテムです。ダッシュボードでコンテンツアイテムを表示し、データベース内のContentItemVersionRecordを調べると、値が正しく設定されていることが確認されます。
ただし、この方法で設定したフィールドではクエリが正しく機能していないようです。 IntegerFieldIndexRecordというレコードが見つかりました。これは、投影がクエリ結果ページを埋めるために使用すると仮定したものです。この場合、TestFieldの値は1(真)ではなく0(偽)のままです。
コンテンツアイテムの編集ページに移動し、単に「保存」をクリックすると、IntegerFieldIndexRecordが正しく更新されます。これは、クエリによって値が取得されることを意味します。プログラムでフィールド値を設定してレコードを更新するにはどうすればよいですか?マイグレーションの
関連セクション:
SchemaBuilder.CreateTable(typeof(TestTypePartRecord).Name, table => table
.ContentPartRecord()
);
ContentDefinitionManager.AlterTypeDefinition(
"TestType",
cfg => cfg
.DisplayedAs("Test Type")
.WithPart(typeof(TitlePart).Name)
.WithPart(typeof(ContainablePart).Name)
.WithPart(typeof(CommonPart).Name)
.WithPart(typeof(IdentityPart).Name)
);
編集:これに対する修正は、フィールド値を変更するたびに、手動でこのコールを使用して、投影インデックスレコードを変更することである。
_fieldIndexService.Set(testResultItem.As<FieldIndexPart>(),
"TestType", // Resolves as TestTypePart, which holds the field
"newField",
"", // Not sure why value name should be empty, but whatever
true, // The value to be set goes here
typeof(bool));
'_contentManager.Publish(TestItem)'を試しましたか? –
以下の答えは問題を解決しました。 FieldIndexPartのハンドラは、フィールドの値が変更されたときにレコードを自動的に変更しないようです。パブリッシングはそれを引き起こすはずですが、パブリッシュしません。 – ub3rman123