@xbstracts/strapi-plugin-content-type-selector
v0.0.8
Published
A Strapi v5 custom field for selecting API content types and optionally choosing entries from those types.
Readme
Content Type Selector Plugin for Strapi v5
A Strapi v5 custom field that lets editors select API collection types and single types, with optional entry selection for the chosen content types.
Package Moved
The package has moved from strapi-plugin-content-type-selector to @xbstracts/strapi-plugin-content-type-selector. Please use the new package name for future installs and updates.
Features
- Adds a
Content Type SelectorJSON custom field to the Strapi Content-Type Builder - Lists API collection types and single types from the current Strapi project
- Supports single or multiple content type selection
- Optionally lets editors choose one or more entries from each selected content type
- Supports allowed content type filtering and default selected content types
- Keeps selected content types and selected entries sortable when multiple selection is enabled
- Shows draft and published entries with status labels
Installation
Install the package in your Strapi v5 project:
npm install @xbstracts/strapi-plugin-content-type-selectorEnable the plugin in config/plugins.ts:
export default () => ({
'content-type-selector': {
enabled: true,
},
});For local plugin development, place the plugin in src/plugins/content-type-selector, then enable it with a local resolve path:
export default () => ({
'content-type-selector': {
enabled: true,
resolve: './src/plugins/content-type-selector',
},
});Build your Strapi admin after installation:
npm run buildUsage
- Open the Strapi Content-Type Builder.
- Add a custom field and choose
Content Type Selector. - Configure the field options for your content model.
- Open an entry in Content Manager and select the content type or types you want to reference.
When content selection is enabled, the field also lets editors select specific entries from each selected content type.
Field Options
Content Type Selection
Allow Multiple Content Types: lets editors select more than one content type. When disabled, the field stores a single content type UID.
Content Selection
Enable Content Selection: lets editors select entries from the chosen content type or types.Allow Multiple Contents: lets editors select multiple entries per content type. When disabled, only one entry can be selected.
Advanced Settings
Allowed Content Types: limits the selector to specific content type UIDs, one per line.Default Content Types: preselects content type UIDs when the field is empty, one per line.Required field: requires at least one content type. When content selection is enabled, it also requires at least one selected entry.
Example UID list:
api::article.article
api::page.page
api::homepage.homepageStored Value
The custom field stores JSON. In single content type mode, the value looks like:
{
"type": "api::article.article",
"contents": ["abc123documentId"]
}In multiple content type mode, the value stores an ordered list of content type UIDs and selected entries per type:
{
"type": ["api::article.article", "api::page.page"],
"contents": {
"api::article.article": ["abc123documentId"],
"api::page.page": ["def456documentId"]
}
}If content selection is disabled, contents is stored as an empty array or object depending on the content type selection mode.
License
MIT License
