diff --git a/docusaurus/docs/dev-docs/api/plugins/admin-panel-api.md b/docusaurus/docs/dev-docs/api/plugins/admin-panel-api.md
index 8525705888..d594e0e529 100644
--- a/docusaurus/docs/dev-docs/api/plugins/admin-panel-api.md
+++ b/docusaurus/docs/dev-docs/api/plugins/admin-panel-api.md
@@ -1,26 +1,28 @@
---
sidebar_label: Admin Panel API
-pagination_prev: dev-docs/plugins/developing-plugins
+pagination_prev: dev-docs/plugins/development/plugin-structure
+toc_max_heading_level: 4
---
# Admin Panel API for plugins
-A Strapi [plugin](/dev-docs/plugins) can interact with both the [back end](/dev-docs/api/plugins/server-api) or the front end of the Strapi app. The Admin Panel API is about the front end part, i.e. it allows a plugin to customize Strapi's [admin panel](/user-docs/intro).
+A Strapi [plugin](/dev-docs/plugins) can interact with both the [back end](/dev-docs/api/plugins/server-api) and the front end of a Strapi application. The Admin Panel API is about the front end part, i.e. it allows a plugin to customize Strapi's [admin panel](/user-docs/intro).
The admin panel is a [React](https://reactjs.org/) application that can embed other React applications. These other React applications are the admin parts of each Strapi plugin.
-To create a plugin that interacts with the Admin Panel API:
-
-1. Create an [entry file](#entry-file).
-2. Within this file, declare and export a plugin interface that uses the [available actions](#available-actions).
-3. Require this plugin interface in a `strapi-admin.js` file at the root of the plugin package folder:
+:::prerequisites
+You have [created a Strapi plugin](/dev-docs/plugins/development/create-a-plugin).
+:::
- ```js title="[plugin-name]/strapi-admin.js"
+The Admin Panel API includes:
- 'use strict';
+- an [entry file](#entry-file) which exports the required interface,
+- [lifecycle functions](#lifecycle-functions) and the `registerTrad()` [async function](#async-function),
+- and several [specific APIs](#available-actions) for your plugin to interact with the admin panel.
- module.exports = require('./admin/src').default;
- ```
+:::note
+The whole code for the admin panel part of your plugin could live in the `/strapi-admin.js|ts` or `/admin/src/index.js|ts` file. However, it's recommended to split the code into different folders, just like the [structure](/dev-docs/plugins/development/plugin-structure) created by the `strapi generate plugin` CLI generator command.
+:::
## Entry file
diff --git a/docusaurus/docs/dev-docs/api/plugins/server-api.md b/docusaurus/docs/dev-docs/api/plugins/server-api.md
index 37cbabebb1..0b02aaf45e 100644
--- a/docusaurus/docs/dev-docs/api/plugins/server-api.md
+++ b/docusaurus/docs/dev-docs/api/plugins/server-api.md
@@ -3,18 +3,29 @@ title: Server API for plugins
sidebar_label: Server API
displayed_sidebar: devDocsSidebar
description: Strapi's Server API for plugins allows a Strapi plugin to customize the back end part (i.e. the server) of your application.
-sidebarDepth: 3
-
---
# Server API for plugins
-A Strapi [plugin](/dev-docs/plugins) can interact with the backend or the [frontend](/dev-docs/api/plugins/admin-panel-api) of the Strapi application. The Server API is about the backend part.
+A Strapi [plugin](/dev-docs/plugins) can interact with both the back end and the [front end](/dev-docs/api/plugins/admin-panel-api) of a Strapi application. The Server API is about the back-end part, i.e. how the plugin interacts with the server part of a Strapi application.
+
+:::prerequisites
+You have [created a Strapi plugin](/dev-docs/plugins/development/create-a-plugin).
+:::
+
+The Server API includes:
+
+- an [entry file](#entry-file) which export the required interface,
+- [lifecycle functions](#lifecycle-functions),
+- a [configuration](#configuration) API,
+- the ability to add [cron](#cron) jobs,
+- and the ability to [customize all elements of the back-end server](#backend-customization).
-Creating and using a plugin interacting with the Server API consists of 2 steps:
+Once you have declared and exported the plugin interface, you will be able to [use the plugin interface](#usage).
-1. Declare and export the plugin interface within the [`strapi-server.js` entry file](#entry-file)
-2. [Use the exported interface](#usage)
+:::note
+The whole code for the server part of your plugin could live in the `/strapi-server.js|ts` or `/server/index.js|ts` file. However, it's recommended to split the code into different folders, just like the [structure](/dev-docs/plugins/development/plugin-structure) created by the `strapi generate plugin` CLI generator command.
+:::
## Entry file
@@ -81,7 +92,7 @@ module.exports = () => ({
## Configuration
-`config` stores the default plugin configuration.
+`config` stores the default plugin configuration. It loads and validates the configuration inputted from the user within the [`./config/plugins.js` configuration file](/dev-docs/configurations/plugins).
**Type**: `Object`
@@ -113,6 +124,10 @@ Once defined, the configuration can be accessed:
- with `strapi.plugin('plugin-name').config('some-key')` for a specific configuration property,
- or with `strapi.config.get('plugin.plugin-name')` for the whole configuration object.
+:::tip
+Run `yarn strapi console` or `npm run strapi console` to access the strapi object in a live console.
+:::
+
## Cron
The `cron` object allows you to add cron jobs to the Strapi instance.
@@ -155,6 +170,12 @@ strapi.cron.jobs
## Backend customization
+All elements of the back-end server of Strapi can be customized through a plugin using the Server API.
+
+:::prerequisites
+To better understand this section, ensure you have read through the [back-end customization](/dev-docs/backend-customization) documentation of a Strapi application.
+:::
+
### Content-types
An object with the [content-types](/dev-docs/backend-customization/models) the plugin provides.
@@ -461,50 +482,54 @@ An object with the [middlewares](/dev-docs/configurations/middlewares) the plugi
**Example:**
-```js title="./src/plugins/my-plugin/strapi-server.js"
-
-"use strict";
-
-module.exports = require('./server');
-```
+```js title="./src/plugins/my-plugin/server/middlewares/your-middleware.js"
-```js title="./src/plugins/my-plugin/server/index.js"
-
-const middlewares = require('./middlewares');
-module.exports = () => ({
- middlewares,
-});
+/**
+ * The your-middleware.js file
+ * declares a basic middleware function and exports it.
+ */
+'use strict';
+module.exports = async (ctx, next) => {
+ console.log("your custom logic")
+ await next();
+}
```
```js title="./src/plugins/my-plugin/server/middlewares/index.js"
-const middlewareA = require('./middleware-a');
-const middlewareB = require('./middleware-b');
+/**
+ * The middleware function previously created
+ * is imported from its file and
+ * exported by the middlewares index.
+ */
+'use strict';
+const yourMiddleware = require('./your-middleware');
module.exports = {
- middlewareA,
- middlewareB,
+ yourMiddleware
};
```
-```js title="./src/plugins/my-plugin/server/middlewares/middleware-a.js"
+```js title="./src/plugins/my-plugin/server/register.js"
-module.exports = (options, { strapi }) => {
- return async (ctx, next) => {
- const start = Date.now();
- await next();
- const delta = Math.ceil(Date.now() - start);
+/**
+ * The middleware is called from
+ * the plugin's register lifecycle function.
+ */
+'use strict';
+const middlewares = require('./middlewares');
- strapi.log.http(`${ctx.method} ${ctx.url} (${delta} ms) ${ctx.status}`);
- };
+module.exports = ({ strapi }) => {
+ strapi.server.use(middlewares.yourMiddleware);
};
```
## Usage
-Once a plugin is exported and loaded into Strapi, its features are accessible in the code through getters. The Strapi instance (`strapi`) exposes top-level getters and global getters.
+Once a plugin is exported and loaded into Strapi, its features are accessible in the code through getters. The Strapi instance (`strapi`) exposes both top-level getters and global getters:
-While top-level getters imply chaining functions, global getters are syntactic sugar that allows direct access using a feature's uid:
+- top-level getters imply chaining functions
+ The plugins configuration file
(e.g., `strapi.plugin('the-plugin-name').controller('the-controller-name'`),
+- global getters are syntactic sugar that allows direct access using a feature's uid
(e.g., `strapi.controller('plugin::plugin-name.controller-name')`).
```js
// Access an API or a plugin controller using a top-level getter
diff --git a/docusaurus/docs/dev-docs/configurations/functions.md b/docusaurus/docs/dev-docs/configurations/functions.md
index 678b9f0a57..3931fbd6cc 100644
--- a/docusaurus/docs/dev-docs/configurations/functions.md
+++ b/docusaurus/docs/dev-docs/configurations/functions.md
@@ -11,6 +11,18 @@ The `./src/index.js` file (or `./src/index.ts` file in a [TypeScript-based](/dev
The functions can be synchronous, asynchronous, or return a promise.
+``` mermaid
+flowchart TB
+ A([The Strapi application starts.]) --> B{"register()"}
+ B -- The Strapi application is setup. --> C
+ C{"bootstrap()"} -- The Strapi back-end server starts. --> D
+ D(Request)
+ D
+ click B "#register"
+ click C "#bootstrap"
+ click D "/dev-docs/backend-customization/requests-responses"
+```
+
## Synchronous function
+
+:::strapi Additional resources
+The Strapi blog features a [tutorial series](https://strapi.io/blog/how-to-create-a-strapi-v4-plugin-server-customization-4-6) about creating a Strapi v4 'Todo' plugin. The [contributors documentation](https://contributor.strapi.io/) can also include additional information useful while developing a Strapi plugin.
+:::
diff --git a/docusaurus/docs/dev-docs/plugins/development/create-a-plugin.md b/docusaurus/docs/dev-docs/plugins/development/create-a-plugin.md
new file mode 100644
index 0000000000..aab1c8efff
--- /dev/null
+++ b/docusaurus/docs/dev-docs/plugins/development/create-a-plugin.md
@@ -0,0 +1,314 @@
+---
+title: Plugin creation & setup
+description: Learn how to create a Strapi plugin and how to start the development servers
+pagination_next: dev-docs/plugins/development/plugin-structure
+---
+
+# Plugin creation and setup
+
+To start developing a Strapi plugin, you need to:
+
+1. create the plugin,
+2. enable the plugin,
+3. install dependencies, build the admin panel, and start the server(s).
+
+:::prerequisites
+You created a Strapi project.
+Use the CLI to create a project:
+
+Run the corresponding command in a terminal window, replacing `my-project` with the name of your choice:
+
+
If created from a Strapi project using the CLI generator, plugins are located in the `src/plugins` folder (see [project structure](/dev-docs/project-structure)).
+
+2. Run the following command in the newly-created plugin directory to install plugin dependencies:
+
+
If created from a Strapi project using the CLI generator, plugins are located in the `src/plugins` folder (see [project structure](/dev-docs/project-structure)).
+
+2. Run the following command in the newly-created plugin directory to install plugin dependencies:
+
+
+
+:::note Notes about the usefulness of the different parts for your specific use case
+- **Server-only plugin**: You can create a plugin that will just use the server part to enhance the API of your application. For instance, this plugin could have its own visible or invisible content-types, controller actions, and routes that are useful for a specific use case. In such a scenario, you don't need your plugin to have an interface in the admin panel.
+
+- **Admin panel plugin vs. application-specific customization**: You can create a plugin to inject some components into the admin panel. However, you can also achieve this by creating a `./src/admin/app.js` file and invoking the `bootstrap` lifecycle function to inject your components. In this case, deciding whether to create a plugin depends on whether you plan to reuse and distribute the code or if it's only useful for a unique Strapi application.
+:::
+
+
+
+:::strapi What to read next?
+The next steps of your Strapi plugin development journey will require you to use any of the Strapi plugins APIs.
+
+2 different types of resources help you understand how to use the plugin APIs:
+
+- The reference documentation for the [Admin Panel API](/dev-docs/api/plugins/admin-panel-api) and [Server API](/dev-docs/api/plugins/server-api) give an overview of what is possible to do with a Strapi plugin.
+- [Guides](/dev-docs/plugins/developing-plugins#guides) cover some specific, use-case based examples.
+:::
diff --git a/docusaurus/docs/dev-docs/plugins/guides/marketplace.md b/docusaurus/docs/dev-docs/plugins/guides/marketplace.md
new file mode 100644
index 0000000000..3ce1887eb6
--- /dev/null
+++ b/docusaurus/docs/dev-docs/plugins/guides/marketplace.md
@@ -0,0 +1,203 @@
+---
+title: Publishing a Strapi plugin to the Marketplace
+# description: todo
+displayed_sidebar: devDocsSidebar
+---
+
+# Publishing your Strapi plugin
+
+_Coming soonβ¦_
+
+:::tip
+Check [this blog post](https://strapi.io/blog/how-to-create-a-strapi-v4-plugin-publish-on-npm-6-6) to learn how to publish your Strapi plugin on npm.
+:::
+
+
+
+
diff --git a/docusaurus/docs/dev-docs/plugins/guides/pass-data-from-server-to-admin.md b/docusaurus/docs/dev-docs/plugins/guides/pass-data-from-server-to-admin.md
new file mode 100644
index 0000000000..bc82d0e3d5
--- /dev/null
+++ b/docusaurus/docs/dev-docs/plugins/guides/pass-data-from-server-to-admin.md
@@ -0,0 +1,101 @@
+---
+title: How to pass data from server to admin panel with a Strapi plugin
+description: Learn how to pass data from server to admin panel with a Strapi plugin
+sidebar_label: Pass data from server to admin
+displayed_sidebar: devDocsSidebar
+---
+
+# How to pass data from server to admin panel with a Strapi plugin
+
+Strapi is **headless**
+
+The CLI will generate some code required to use your plugin, which includes the following:
+
+- the [content-type schema](/dev-docs/backend-customization/models#model-schema)
+- and a basic [controller](/dev-docs/backend-customization/controllers), [service](/dev-docs/backend-customization/services), and [route](/dev-docs/backend-customization/routes) for the content-type
+
+:::tip
+You may want to create the whole structure of your content-types either entirely with the CLI generator or by directly creating and editing `schema.json` files. We recommend you first create a simple content-type with the CLI generator and then leverage the [Content-Type Builder](/user-docs/content-type-builder) in the admin panel to edit your content-type.
+
+If your content-type is not visible in the admin panel, you might need to set the `content-manager.visible` and `content-type-builder.visible` parameters to `true` in the `pluginOptions` object of the content-type schema:
+
+Making a plugin content-type visible in the admin panel:
+
+The following highlighted lines in an example `schema.json` file show how to make a plugin content-type visible to the Content-Type Builder and Content-Manager:
+
+```json title="/server/content-types/my-plugin-content-type/schema.json" {13-20} showLineNumbers
+{
+ "kind": "collectionType",
+ "collectionName": "my_plugin_content_types",
+ "info": {
+ "singularName": "my-plugin-content-type",
+ "pluralName": "my-plugin-content-types",
+ "displayName": "My Plugin Content-Type"
+ },
+ "options": {
+ "draftAndPublish": false,
+ "comment": ""
+ },
+ "pluginOptions": {
+ "content-manager": {
+ "visible": true
+ },
+ "content-type-builder": {
+ "visible": true
+ }
+ },
+ "attributes": {
+ "name": {
+ "type": "string"
+ }
+ }
+}
+
+```
+
+
+
+
+
+
+
+ . # root of the plugin folder (e.g., /src/plugins/my-plugin)
+
+ βββ admin # Admin panel part of your plugin.
+ β βββ src
+ β βββ components # Contains your front-end components
+ β β βββ Initializer
+ β β β βββ index.js # Plugin initializer
+ β β βββ PluginIcon
+ β β βββ index.js # Contains the icon of your plugin in the main navigation
+ β βββ pages # Contains the pages of your plugin
+ β β βββ App
+ β β β βββ index.js # Skeleton around the actual pages
+ β β βββ HomePage
+ β β βββ index.js # Homepage of your plugin
+ β βββ translations # Translations files to make your plugin i18n-friendly
+ β β βββ en.json
+ β β βββ fr.json
+ β βββ utils
+ β β βββ getTrad.js # getTrad function to return the corresponding plugin translations
+ β βββ index.js # Main setup of your plugin, used to register elements in the admin panel
+ β βββ pluginId.js # pluginId variable computed from package.json name
+ βββ node_modules
+ βββ server # Back-end part of your plugin
+ β βββ config
+ β β βββ index.js # Contains the default server configuration
+ β βββ content-types # Content-types specific to your plugin
+ β β βββ index.js # Loads all the plugin's content-types
+ β βββ controllers # Controllers specific to your plugin
+ β β βββ index.js # Loads all the plugin's controllers
+ β β βββ my-controller.js # Custom controller example. You can rename it or delete it.
+ β βββ middlewares # Middlewares specific to your plugin
+ β β βββ index.js # Loads all the plugin's middlewares
+ β βββ policies # Policies specific to your plugin
+ β β βββ index.js # Loads all the plugin's policies
+ β βββ routes # Routes specific to your plugin
+ β β βββ index.js # Contains an example route for the my-controller custom controller example
+ β βββ services # Services specific to your plugin
+ β β βββ index.js # Loads all the plugin's services
+ β β βββ my-service.js # Custom service example. You can rename it or delete it.
+ β βββ bootstrap.js # Function that is called right after the plugin has registered
+ β βββ destroy.js # Function that is called to clean up the plugin after Strapi instance is destroyed
+ β βββ index.js # Loads the code for all the server elements
+ β βββ register.js # Function that is called to load the plugin, before bootstrap.
+ βββ package.json
+ βββ README.md
+ βββ strapi-admin.js # Entrypoint for the admin panel (front end)
+ βββ strapi-server.js # Entrypoint for the server (back end)
+
+
+
+
+
+
+
+ . # root of the plugin folder (e.g., /src/plugins/my-plugin)
+
+ βββ admin # Admin panel part of your plugin.
+ β βββ src
+ β βββ components # Contains your front-end components
+ β β βββ Initializer
+ β β β βββ index.tsx # Plugin initializer
+ β β βββ PluginIcon
+ β β βββ index.tsx # Contains the icon of your plugin in the main navigation
+ β βββ pages # Contains the pages of your plugin
+ β β βββ App
+ β β β βββ index.tsx # Skeleton around the actual pages
+ β β βββ HomePage
+ β β βββ index.tsx # Homepage of your plugin
+ β βββ translations # Translations files to make your plugin i18n-friendly
+ β β βββ en.json
+ β β βββ fr.json
+ β βββ utils
+ β β βββ getTrad.ts # getTrad function to return the corresponding plugin translations
+ β βββ index.tsx # Main setup of your plugin, used to register elements in the admin panel
+ β βββ pluginId.tsx # pluginId variable computed from package.tsxon name
+ βββ dist # Build of the backend
+ βββ node_modules
+ βββ server # Back-end part of your plugin
+ β βββ config
+ β β βββ index.ts # Contains the default server configuration
+ β βββ content-types # Content-types specific to your plugin
+ β β βββ index.ts # Loads all the plugin's content-types
+ β βββ controllers # Controllers specific to your plugin
+ β β βββ index.ts # Loads all the plugin's controllers
+ β β βββ my-controller.ts # Custom controller example. You can rename it or delete it.
+ β βββ middlewares # Middlewares specific to your plugin
+ β β βββ index.ts # Loads all the plugin's middlewares
+ β βββ policies # Policies specific to your plugin
+ β β βββ index.ts # Loads all the plugin's policies
+ β βββ routes # Routes specific to your plugin
+ β β βββ index.ts # Contains an example route for the my-controller custom controller example
+ β βββ services # Services specific to your plugin
+ β β βββ index.ts # Loads all the plugin's services
+ β β βββ my-service.ts # Custom service example. You can rename it or delete it.
+ β βββ bootstrap.ts # Function that is called right after the plugin has registered
+ β βββ destroy.ts # Function that is called to clean up the plugin after Strapi instance is destroyed
+ β βββ index.ts # Loads the code for all the server elements
+ β βββ register.ts # Function that is called to load the plugin, before bootstrap.
+ βββ custom.d.ts # Generated types
+ βββ package.json
+ βββ README.md
+ βββ strapi-admin.js # Entrypoint for the admin panel (front end)
+ βββ strapi-server.js # Entrypoint for the server (back end)
+ βββ tsconfig.json # TypeScript compiler options for the admin panel part
+ βββ tsconfig.server.json # TypeScript compiler options for the server part
+ config/plugins.js|ts
:
+
+
+
+ More details can be found in the plugins configuration documentation. +
+ + ) +} + +export function HeadlessCms() { + return ( ++ A headless CMS is a Content Management System that separates the presentation layer (i.e., the front end, where content is displayed) from the back end (where content is managed). +
++ Strapi is a headless CMS that provides: +