Skillpedia
واجهات API والخوادم (backend)8.1k · #12598

webiny-api-cms-content-models

ما الذي تفعله

ترشد هذه المهارة ذكاءك عند إنشاء نماذج محتوى CMS في مشروع Webiny أو تغييرها عبر الكود. وهي لمطورين يريدون تعريف بنى بياناتهم في كود مُدار بالإصدارات.

متى تستخدمها

  • ✓عندما تريد إنشاء نموذج محتوى مثل المنتجات أو مقالات المدونة بالكود.
  • ✓عندما تحتاج الحقول إلى تحقق أو مراجع إلى نماذج أخرى.
  • ✓عندما تحتاج إلى اختيار العرض المناسب في الإدارة لنوع حقل.

رابط المهارة

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/content-models/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/content-models/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“أنشئ نموذج محتوى للمنتجات بالكود، يتضمن الاسم والسعر ومرجعًا إلى نموذج الفئة.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تُظهر المهارة صنف نموذج يستخدم منشئًا متسلسلًا لتعريف الحقول والتخطيطات وحقول العنوان وأسماء الـAPI. ويُسجَّل النموذج في ملف إعدادات المشروع.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Creating Content Models via Code

TL;DR

Content models are created using the ModelFactory pattern. You define a class implementing ModelFactory.Interface, use the fluent ModelFactory.Builder API to declare fields, validators, layout, and API names, then export with ModelFactory.createImplementation(). Register in webiny.config.tsx as <Api.Extension>.

The ModelFactory Pattern

Every code-based content model follows the same structure:

import { ModelFactory } from "webiny/api/cms/model";

class MyModelImpl implements ModelFactory.Interface {
  async execute(builder: ModelFactory.Builder) {
    return [
      builder
        .public({ modelId: "myModel", name: "My Model", group: "ungrouped" })
        .description("Description of the model")
        .fields(fields => ({
          // field definitions here
        }))
        .layout([/* row definitions */])
        .titleFieldId("fieldId")
        .singularApiName("MyModel")
        .pluralApiName("MyModels")
    ];
  }
}

export default ModelFactory.createImplementation({
  implementation: MyModelImpl,
  dependencies: []
});

Register in webiny.config.tsx:

<Api.Extension src={"/extensions/MyModel.ts"} />

YOU MUST include the full file path with the .ts extension in the src prop. For example, use src={"/extensions/MyModel.ts"}, NOT src={"/extensions/MyModel"}. Omitting the file extension will cause a build failure.

YOU MUST use export default for the createImplementation() call when the file is targeted directly by an Extension src prop. Using a named export (export const MyModel = ...) will cause a build failure. Named exports are only valid inside files registered via createFeature.

Model Configuration Methods

Method Purpose
.public({ modelId, name, group }) Creates a public model (accessible via Read API). modelId is the internal DB identifier. group organizes it in the Admin sidebar.
.description("...") Model description shown in Admin UI
.fields(fields => ({ ... })) Define all fields using the fluent field builder
.layout([["field1", "field2"], ["field3"]]) Arrange fields in rows in the Admin editor. Each inner array is one row.
.titleFieldId("name") Which field to use as the entry's display title
.descriptionFieldId("message") Which field to use as the entry's description
.singularApiName("Product") Singular name for GraphQL queries (e.g., getProduct)
.pluralApiName("Products") Plural name for GraphQL queries (e.g., listProducts)
.singleEntry() Makes the model a singleton (only one entry can exist). Automatically adds
الأسئلة الشائعة

كيف يُسجَّل النموذج؟

كامتداد API في ملف webiny.config، مع المسار الكامل للملف وامتداد .ts.

هل يمكن تداخل الحقول؟

نعم. تغطي المهارة التخطيطات المتداخلة داخل حقول الكائنات والمناطق الديناميكية.

هل تغطي اختيار عرض الحقول؟

نعم. تشرح أي عرض في الإدارة يُستخدم لكل نوع حقل.

التفاصيل

الوصف الأصلي من المؤلف

Creating Headless CMS content models via code using the ModelFactory pattern. Use this skill when the developer wants to create, modify, or understand content model definitions, define fields and validators, set up reference fields between models, configure field layouts (including nested layouts inside object or dynamicZone fields), pick the correct Admin UI renderer for a field type (textInput/textInputs, lexicalEditor/lexicalEditors, file/files, objectAccordionSingle/objectAccordionMultiple, etc.), or work with the ModelFactory builder API. Also covers field types (text, longText, number, b

repo: webiny/webiny-js

الشعبية

نجوم GitHub
8.1k
الترتيب
#12598
الترخيص
—
آخر تحديث
2‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة