mattmilburn / strapi-plugin-menus

A plugin for Strapi CMS to customize the structure of menus and menu items.
MIT License
112 stars 29 forks source link

Configured custom attributes not appearing on edit screen #131

Open aaronibrahim opened 1 year ago

aaronibrahim commented 1 year ago

Hey all,

Thanks for hearing out my problem. I'm hoping I just overlooked something silly that you'll catch right away.

Setup

strapi-plugin-menus version 1.5.0
Strapi version 4.13.6
Node version 18.8.0
Database mysql

strapi-server.ts

Note: I have also tried naming it strapi-server.js and used a module.exports = construct for the export.

// ./src/extensions/menus/strapi-server.ts
'use strict';

export default plugin => {
  // Get current `MenuItem` attributes.
  const defaultAttrs = plugin.contentTypes[ 'menu-item' ].schema.attributes;

  // Define custom attributes for `MenuItem` the same way they would be defined
  // on any other schema.
  const customAttrs = {
    bold_display: {
      type: 'boolean',
    },
  };

  // Extend the `MenuItem` content type with custom attributes.
  plugin.contentTypes[ 'menu-item' ].schema.attributes = {
    ...defaultAttrs,
    ...customAttrs,
  };

  return plugin;
};

plugins.ts

// ./config/plugins.ts

export default {
    menus: {
      config: {
        layouts: {
          menuItem: { // This is the menu item edit panel.
            link: [ // This is the "link" tab in the menu item edit panel.
              {
                input: {
                  label: 'Display Menu Item in Bold',
                  name: 'bold_display',
                  type: 'boolean',
                },
                grid: {
                  col: 6,
                },
              },
            ],
          },
        },
      },
    },    
  };

Steps to reproduce:

  1. Rebuild the admin panel by running yarn build
  2. Start the strapi server
  3. Navigate to Menus in strapi admin's left navigation
  4. Create a menu
  5. Click add menu item

Outcome

Settings_—_Edit_menu

I am not seeing the bold_display filed in my menu item.

What am I doing wrong?

mattmilburn commented 1 year ago

Hi @aaronibrahim In your config/plugins.ts file, try changing the input.type to bool instead of boolean.

In the docs there is a Supported Field Types section with a table that describes the schema type vs the input type. Sorry I know that's confusing. It's setup this way because Strapi schema uses boolean as the type, but Strapi's GenericInput component usesbool.