objects タイプを使用すると、テーマ設定 に、名前と URL を持つリンクや、それぞれがリンクを含むセクションなど、定義した構造を持つオブジェクトのリストを持たせることができます。管理者はオブジェクトエディターでリストを編集し、Discourse はスキーマに基づいて各オブジェクトを検証します。これは古い json_schema タイプを置き換えます。
objects 設定を定義する
設定に type: objects、default、および schema を追加します。
links:
type: objects
default: []
schema:
name: link
identifier: name
properties:
name:
type: string
url:
type: string
defaultは設定の初期値です。空のリスト、またはスキーマに一致するオブジェクトのリストです。schema.nameは単一のオブジェクトの名前です。エディターでは、例えば「link 1」のように、この名前でオブジェクトにラベルを付けます。schema.identifierはオプションです。リンク名のように、オブジェクトのラベル付けに使用するプロパティを指定します。指定しない場合、エディターではschema.nameが使用されます。schema.propertiesには、各オブジェクトが持つことができるプロパティをリストアップします。すべてのプロパティにはtypeが必要です。
プロパティのタイプ
-
string: テキスト。textarea: trueを設定すると、拡大表示可能なテキストエリアが使用されます:description: type: string textarea: true validations: max_length: 500 -
integer: 整数。 -
float: 小数を含む数値。 -
boolean:trueまたはfalse。 -
enum:choicesにリストされた値のいずれか:size: type: enum choices: - small - medium - large -
datetime: タイムゾーン付きの ISO 8601 形式の日付と時刻(例:2026-01-01T10:00:00Z)。 -
upload: アップロードされたファイル。テーマコードは URL を受け取ります。 -
icon: Discourse アイコンセットからのアイコン名。選択したアイコンはスプライトシートに自動的に追加されるため、手動で登録する必要はありません。 -
categories: カテゴリ ID のリスト。 -
groups: グループ ID のリスト。 -
tags: タグ名のリスト。 -
objects: オブジェクトのネストされたリスト。以下の「ネストされたオブジェクト」を参照してください。
tags の場合、設定 API はタグ ID も受け入れ、名前で保存します。テーマコードでは、tags プロパティを持つ各オブジェクトに、訪問者に表示される各選択タグの id と name を含む tag_objects 配列も追加されます。これにより、CSS などで ID を使ってタグをターゲットできます。
既定値
スキーマが定義されると、default にそれと一致するオブジェクトを持たせることができます:
links:
type: objects
default:
- name: Guidelines
url: /guidelines
- name: FAQ
url: /faq
schema:
name: link
identifier: name
properties:
name:
type: string
url:
type: string
必須プロパティ
プロパティはデフォルトでオプションです。required: true を追加して必須にします:
properties:
name:
type: string
required: true
url:
type: string
空の string、datetime、icon の値、および空の categories、groups、tags リストは、未入力と見なされます。必須プロパティではこれらが拒否され、オプションプロパティでは検証がスキップされます。false は設定済みと見なされます。
検証
一部のタイプでは validations キーを受け入れます:
properties:
url:
type: string
required: true
validations:
max_length: 2048
url: true
string プロパティの場合:
min_length: 最小文字数。max_length: 最大文字数。url:trueの場合、値は URL である必要があります。絶対http、https、ftpURL、mailto:リンク、/で始まるパス、#アンカーが受け入れられます。
integer および float プロパティの場合:
min: 最小値。max: 最大値。
tags、groups、categories プロパティの場合:
min: 選択項目の最小数。max: 選択項目の最大数。
グループメンバーシップの解決
テーマコードでは、現在のユーザーが選択されたグループのいずれかに属しているかどうかだけを知ることがよくあります。currentUser.groups は、ユーザーが表示できるグループのみを含めるため、これに信頼して回答できません。groups プロパティに resolve_group_membership: true を追加して、サーバー側で解決します:
menu_sections:
type: objects
default:
- name: Staff tools
groups:
- 3
schema:
name: menu section
properties:
name:
type: string
groups:
type: groups
resolve_group_membership: true
管理 UI と保存された値は groups リストを保持します。フロントエンドの settings オブジェクトでは、Discourse は各オブジェクト内のグループ ID を、プロパティ名に user_in_ を接頭辞として付けたブール値に置き換えます:
for (const section of settings.menu_sections) {
if (section.user_in_groups) {
// The user is in at least one of the selected groups.
}
}
オブジェクトスキーマ内では、このオプションは type: groups プロパティでのみ機能します。また、ネストされたオブジェクト内や、logged_in_users や anonymous_users などの自動グループでも機能します。
ネストされたオブジェクト
type: objects と独自の schema を持つプロパティは、ネストされたリストを保持します:
sections:
type: objects
default:
- name: Getting started
links:
- name: Guidelines
url: /guidelines
- name: FAQ
url: /faq
schema:
name: section
identifier: name
properties:
name:
type: string
required: true
links:
type: objects
schema:
name: link
identifier: name
properties:
name:
type: string
url:
type: string
設定の説明とプロパティのラベル
テーマの locales/en.yml で設定を説明し、プロパティにラベルを付けます。上記の sections 設定の場合:
en:
theme_metadata:
settings:
sections:
description: Sections shown in the sidebar
schema:
properties:
name:
label: Name
description: The section's heading
links:
name:
label: Name
description: The link text
url:
label: URL
description: Where the link goes
ネストされたプロパティのラベルは、そのコレクション(ここでは links)の名前の下に配置します。
翻訳可能なテキスト
管理画面でオブジェクトエディターに入力されたテキストを管理者が翻訳できるようにするには、必須の translation_key 文字列プロパティを宣言し、各テキストプロパティに translatable: true を追加します:
links:
type: objects
default:
- translation_key: guidelines
label: Community guidelines
schema:
name: link
properties:
translation_key:
type: string
required: true
label:
type: string
translatable: true
各翻訳可能なフィールドは、links.guidelines.label のようなテーマ翻訳となり、管理 UI で管理者が管理します。キーのルール、ネストされたオブジェクト、コードでのテキストの読み取り、既存のコンポーネントの更新については、翻訳可能な設定 を参照してください。
このドキュメントはバージョン管理されています - GitHub で変更を提案してください: on github。



