네, objects 배열의 최대 개수를 제한하는 것을 말씀하신 것입니다.
현재 공식적으로 지원되지 않으므로, 사용자 정의 프라이빗 테마 컴포넌트에서 해당 기능을 확장했습니다. 설정은 다음과 같습니다(참고용).
최대 배열 개수 제한 설정:
themes/quectel-custom-homepage/settings.yml
banner_images:
type: objects
default: []
schema:
name: "배너 이미지"
max: 9 // 배열의 최대 개수를 제한하는 확장 설정
identifier: image_url
properties:
image_url:
type: upload
required: true
link_url:
type: string
min: 0
max: 1023
확장된 구체적인 코드:
themes/quectel-custom-homepage/javascripts/discourse/api-initializers/quectel-custom-homepage.gjs
import { action } from "@ember/object";
import { apiInitializer } from "discourse/lib/api";
import classPrepend from "discourse/lib/class-prepend";
import { i18n } from "discourse-i18n";
export default apiInitializer(() => {
// classPrepend를 사용하여 SchemaSettingNewEditor 컴포넌트를 확장하여 objects 유형의 max 제한을 지원하도록 합니다.
// 관리자 컨텍스트에서만 해당 컴포넌트를 로드합니다.
let SchemaSettingNewEditor;
try {
SchemaSettingNewEditor =
require("discourse/admin/components/schema-setting/editor").default;
} catch {
// 비관리자 사용자는 해당 컴포넌트를 로드할 수 없으므로 확장을 건너뜁니다.
return;
}
classPrepend(SchemaSettingNewEditor, (Superclass) => {
return class extends Superclass {
@action
addItem() {
// max 제한에 도달했는지 확인합니다.
const maxLimit = this.args.setting.max || this.activeSchema?.max;
if (maxLimit && this.activeData.length >= maxLimit) {
this.validationErrorMessage = i18n(
themePrefix("theme_settings.errors.objects_value_not_valid_max"),
{
count: maxLimit,
}
);
return;
}
return super.addItem(...arguments);
}
@action
addChildItem(propertyName, parentNodeIndex) {
const propertySchema = this.activeSchema.properties[propertyName];
// max 제한에 도달했는지 확인합니다.
if (
propertySchema?.max &&
this.activeData[parentNodeIndex][propertyName].length >=
propertySchema.max
) {
this.validationErrorMessage = i18n(
themePrefix("theme_settings.errors.objects_value_not_valid_max"),
{
count: propertySchema.max,
}
);
return;
}
return super.addChildItem(...arguments);
}
};
});
});
테마 번역 설정:
themes/quectel-custom-homepage/locales/zh_CN.yml
zh_CN:
theme_settings:
errors:
objects_value_not_valid_max: "개수는 %{count}개를 초과할 수 없습니다"
구체적인 효과:
- 오류 메시지
- 더 이상 추가할 수 없음
