新しいProseMirrorエディターでカスタムフィールドが挿入されない

こんにちは!

イベントのカスタムタグと新しいWYSIWYG ProseMirrorエディターに問題があります。イベントフォームから入力されたカスタムフィールドが生成された文字列に存在しません。Markdownエディターでは以前と同じように機能します。

再現手順:

  1. Discourse Calendarプラグインを有効にする
  2. プラグイン設定でカスタムフィールドを1つ追加する
  3. 新しい投稿のフォームを開く
  4. ProseMirrorエディターを選択する
  5. カスタムフィールドに値を持つイベントを作成する(オプション > イベントを作成)
  6. イベントを検証する
  7. Markdownエディターに切り替える

現在の状況

カスタムフィールドが [event] タグにありません。

期待される動作

カスタムフィールドが [event] タグに存在する必要があります。

備考

ProseMirrorエディターではなくMarkdownエディターから開始して同じことを行うと、カスタムフィールドが [event] タグに存在します。

「いいね!」 2

新しいイベントを検証する際の toolbarEvent の状況を少し調査しました。addText() メソッドは、どちらの場合も正しいマークアップを受け取っているようです。

[event start="2025-09-26 18:00" status="public" timezone="Europe/Paris" end="2025-09-26 19:00" cf_1="abcd"]\n[/event]

問題の再現に役立つ場合は、QUnit テストを以下に示します。

// plugins/discourse-calendar/test/acceptance/post-event-builder-custom-tags-test.js
import { click, find, visit, fillIn } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { i18n } from "discourse-i18n";

acceptance("Discourse Calendar - New event form with custom fields", function (needs) {
  needs.user({ admin: true, can_create_discourse_post_event: true });
  needs.settings({
    discourse_local_dates_enabled: true,
    calendar_enabled: true,
    discourse_post_event_enabled: true,
    discourse_post_event_allowed_on_groups: "",
    discourse_post_event_allowed_custom_fields: "my_custom_field",
    coopaname_integration_enabled: false,
  });

  test("filling the form with MD editor fills the custom fields", async function (assert) {
    await ensureEventTagHasFields(assert, "md");
  });

  test("filling the form with WYSIWYG editor fills the custom fields", async function (assert) {
    await ensureEventTagHasFields(assert, "wysiwyg");
  });
});

async function ensureEventTagHasFields(assert, editorType) {
  await visit("/");
  await click("#create-topic");
  const categoryChooser = selectKit(".category-chooser");
  await categoryChooser.expand();
  await categoryChooser.selectRowByValue(2);

  await switchEditorTo(editorType);

  await click(".toolbar-menu__options-trigger");
  await click(`button[title='${i18n("discourse_post_event.builder_modal.attach")}']`);
  await fillIn("input.custom-field-input", "some value");
  await click(".d-modal__footer > button");

  await switchEditorTo("md");

  const fields = ["start", "status", "timezone", "myCustomField"];
  const content = await find(".d-editor-input").value;

  fields.forEach((field) => {
    assert.true(content.includes(`${field}="`), `${field} is present in event tag`);
  });
}

async function switchEditorTo(type) {
  const editorSwitch = find("button.composer-toggle-switch");
  const isInMarkdown = editorSwitch.attributes["aria-checked"].value === "false";
  if ((isInMarkdown && type === "wysiwyg") || (!isInMarkdown && type === "md")) {
    await click(editorSwitch);
  }
}

もちろんです。テストからこの行を削除してください coopaname_integration_enabled: false, :upside_down_face:

プラグインに同じ機能を持つものが見つからなかったので、何が問題なのか見つけるのが難しいです。

フォームを検証すると、正しいテキストで this.args.model.toolbarEvent.addText() が呼び出されます。

いくつかの console.log™ により、text-manipulation.js#addText() にたどり着きました。ここで this.convertFromMarkdown(text) が呼び出されます。問題はここから来ているようです。スキーマのようなものが強制されており、カスタムフィールドが含まれていません。

まだ調べています :shovel:

問題は、エディタ拡張機能 discourse-calendar/assets/javascripts/discourse/pre-initializers/rich-editor-extension.js にあります。convertFromMarkdown() が使用する属性のリストは、EVENT_ATTRIBUTES 定数で定義されています。カスタムフィールドをリストに追加すると、これは機能します。

const EVENT_ATTRIBUTES = {
  // ...
  chatChannelId: { default: null },
  myCustomField: {default: null}
};

このファイルにはカスタムフィールドに関する記述がありません。すべてのカスタムフィールドでこの定数を完成させる方法がわかりません。拡張機能はプロセスの早い段階で登録されるようです。

何かアイデアがあれば教えてください。無効にできない新しいエディタでプラグインが使用できなくなり、Discourse 3.4 で立ち往生しています。

リッチエディターでは、現時点ではカスタムフィールドはサポートされていません。今後の進め方について調査します。

設定可能です。管理者の場合、コンソール経由で SiteSettings.rich_editor = false を設定できます。これは、このような場合に最後の手段としてまだ利用可能です。

「いいね!」 1

ご返信ありがとうございます。ひとまずエディターを無効にします。