Customize content-manager with strapi v4

I’m looking for a solution to customize the content-manager in Strapi v4.

My need is to add business logic/control to prevent input errors by admin user.
(For exemple : An entry of type A can be associated with an entry of type B only if the attribute “foo” of the B entry is equals to “xxxxxx”)

I feel like it’s not possible to do this with strapi v4.

So there is a way to do that ? Is there an example ?

In advance thanks for your answer.

I have found a solution…
I don’t know if it’s the best solution but it seems elegant to me.
(Please note that I am not a nodejs expert. )

I created the file src/extensions/content-manager/strapi-server.js

const { getService } = require('@strapi/plugin-content-manager/server/utils');

module.exports = (plugin) => {
    const controller = plugin.controllers['collection-types'];

    // Save the original create controller action
    controller.strapiCreate = controller.create;

    // extend action create
    controller.create = async (ctx) => {
        const { model } = ctx.params;
        const { body } = ctx.request;

        const A_MODEL = "api::a.a";
        const B_MODEL = "api::b.b";

        const entityManager = getService('entity-manager');

        if (model == A_MODEL ) {
            // business logic using entityManager.findOne, find...etc.
            if (/* test if there is a functionnal error */) {
                return ctx.badRequest("An error message");
            }
        }

        // Call to the saved create controller action
        controller.strapiCreate(ctx);
    };

    return plugin;
};
1 Like

This works if the last line is return controller.strapiCreate(ctx)

see Content-manager extension getting 404 error

I don’t get why this plugin does not call the services and controllers defined in api//services etc.

This leads to duplicate logic at least, and a lot of confusion. Furthermore, I don’t expect my editors and authors to use REST API :confused:

Did you report this as a bug in the Strapi repository?

Not sure if I should. Perhaps is it something that is there “by design”? I mean kind of a feature, that the two content creation systems work in different ways? I wouldn’t design the API this way, but perhaps there is a reason.

I am new to Strapi, so I’m not sure if the right place to discuss this is the GitHub issues or this forum

You can ask either here or in the Discord channel, but if it is a bug, go straight forward to the repo.