umbraco-property-value-preset について
umbraco-property-value-presetは、Umbracoのプロパティ値プリセットを作成するスキルです。プロパティエディターの既定値として、設定に基づく値や非同期の値、重み付けした複数プリセットを扱う方法を案内します。
主な機能
- 01プロパティ値プリセットのマニフェスト作成
- 02プリセット値APIの実装
- 03固定値または設定依存の既定値
- 04非同期の既定値への対応
- 05重みによる複数プリセットの順序設定
活用シーン
- 01新規コンテンツの初期値設定
- 02エディター設定に基づく既定値の決定
- 03APIからの既定値取得
- 04指定順でのプリセットの組み合わせ
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ umbraco/ umbraco-cms-backoffice-skills --skill umbraco-property-value-presetインストール後、Claude Code で/umbraco-property-value-presetを入力して読み込まれたか確認します。
詳細
Umbraco プロパティ値プリセット
これは何ですか?
プロパティ値プリセットは、ユーザーが新しいコンテンツを作成するときに既定値を提供します。API を使用して特定のプロパティエディターにプリセット値を供給し、適切な既定値による効率的なコンテンツ作成を可能にします。複数のプリセットは weight プロパティを使用して連携し、値を段階的に変更できます。
ドキュメント
実装する前に、常に最新のドキュメントを取得してください:
- メインドキュメント: https://docs.umbraco.com/umbraco-cms/extend-your-project/backoffice-extensions/extending-overview/extension-types/property-value-preset
- プロパティエディター: https://docs.umbraco.com/umbraco-cms/extend-your-project/backoffice-extensions/property-editors
- Foundation: https://docs.umbraco.com/umbraco-cms/extend-your-project/backoffice-extensions/foundation
- 拡張機能レジストリ: https://docs.umbraco.com/umbraco-cms/extend-your-project/backoffice-extensions/extending-overview/extension-registry
ワークフロー
- ドキュメントを取得 - 上記の URL に対して WebFetch を使用します
- 質問する - どのプロパティエディターですか? 既定値は何ですか? 静的ですか、動的ですか?
- ファイルを生成 - 最新のドキュメントに基づいてマニフェスト + プリセット API を作成します
- 説明 - 何が作成されたか、およびテスト方法を示します
最小限の例
マニフェスト (manifests.ts)
import type { ManifestPropertyValuePreset } from '@umbraco-cms/backoffice/extension-registry';
const manifest: ManifestPropertyValuePreset = {
type: 'propertyValuePreset',
alias: 'My.PropertyValuePreset.DefaultText',
name: 'Default Text Preset',
api: () => import('./default-text-preset.js'),
forPropertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
};
export const manifests = [manifest];
プリセットの実装 (default-text-preset.ts)
import type { UmbPropertyValuePresetApi } from '@umbraco-cms/backoffice/property';
export class DefaultTextPreset implements UmbPropertyValuePresetApi {
async processValue(value: unknown, config: unknown): Promise<unknown> {
// Return default if no value exists
return value ? value : 'Default text value';
}
destroy() {
// Cleanup if needed
}
}
export default DefaultTextPreset;
構成に基づく動的な既定値
import type { UmbPropertyValuePresetApi, UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property';
export class DynamicPreset implements UmbPropertyValuePresetApi {
async processValue(value: unknown, config: UmbPropertyEditorConfigCollection): Promise<unknown> {
if (value) return value;
// Use configuration to determine default
const defaultFromConfig = config?.getValueByAlias('defaultValue');
return defaultFromConfig || 'Fallback default';
}
destroy() {}
}
export default DynamicPreset;
非同期の既定値 (例: API から)
import type { UmbPropertyValuePresetApi } from '@umbraco-cms/backoffice/property';
export class ApiPreset implements UmbPropertyValuePresetApi {
async processValue(value: unknown, config: unknown): Promise<unknown> {
if (value) return value;
// Fetch default from server
const response = await fetch('/api/defaults/text');
const data = await response.json();
return data.defaultValue;
}
destroy() {}
}
export default ApiPreset;
スキーマエイリアスによるターゲット指定
const manifest: ManifestPropertyValuePreset = {
type: 'propertyValuePreset',
alias: 'My.PropertyValuePreset.JsonDefault',
name: 'JSON Default Preset',
api: () => import('./json-preset.js'),
forPropertyEditorSchemaAlias: 'Umbraco.Plain.Json', // Target schema instead of UI
};
weight を使用した複数のプリセット
// First preset (runs first due to lower weight)
const basePreset: ManifestPropertyValuePreset = {
type: 'propertyValuePreset',
alias: 'My.PropertyValuePreset.Base',
name: 'Base Preset',
weight: 100,
api: () => import('./base-preset.js'),
forPropertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
};
// Second preset (runs after, can modify base value)
const enhancedPreset: ManifestPropertyValuePreset = {
type: 'propertyValuePreset',
alias: 'My.PropertyValuePreset.Enhanced',
name: 'Enhanced Preset',
weight: 200,
api: () => import('./enhanced-preset.js'),
forPropertyEditorUiAlias: 'Umb.PropertyEditorUi.TextBox',
};
日付の既定値の例
export class TodayDatePreset implements UmbPropertyValuePresetApi {
async processValue(value: unknown, config: unknown): Promise<unknown> {
if (value) return value;
return new Date().toISOString().split('T')[0]; // Today's date
}
destroy() {}
}
export default TodayDatePreset;
以上です! 常に最新のドキュメントを取得し、例を最小限に保ち、完全に動作するコードを生成してください。
コメント
Markdown 対応