mattmilburn / strapi-plugin-menus

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

Extended MenuItems not saving to db #146

Open mattdjenkinson opened 10 months ago

mattdjenkinson commented 10 months ago

Hey, looking for some help with this plugin.

My extended MenuItems don't save to the DB. I can't see the new columns created in the menu_items table, even after a re-build.

Strapi: 4.15.5 Menus: 1.6.0 DB: mysql Node: 18.17.0

I have added the strapi-server file;

"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 = {
    is_external: {
      type: "boolean",
    },
  };

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

  return plugin;
};

and edited my plugins.ts;

  menus: {
    config: {
      maxDepth: 3,
      layouts: {
        menuItem: {
          link: [
            {
              input: {
                label: "Is External",
                name: "is_external",
                type: "bool",
                description: "Is this a link to an external page?",
              },
              grid: {
                col: 6,
              },
            },
          ],
        },
      },
    },
  },

Not sure what I'm doing wrong 🤔

Any help would be appreciated.

Thanks

kolyabres commented 9 months ago

I have the same issue.

  "menus": {
    enabled: true,
    config: {
      maxDepth: 2,
      layouts: {
        menuItem: {
          link: [
            {
              input: {
                label: 'German title',
                name: 'title_de',
                type: 'text',
                required: true
              },
            },
          ],
        },
      },
    },
  },
NixFront commented 8 months ago

+1 similar issue facing

Dominic-Preap commented 7 months ago

Are you using Strapi Typescript? if you are using Typescript, you need to update from strapi-server file from js to ts, like example below.

// ./src/extensions/menus/strapi-server.ts
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 = {
    example_title: {
      type: 'string'
    },
    example_bool: {
      type: 'boolean'
    },
    example_enum: {
      type: 'enumeration',
      enum: ['col1', 'col2', 'col3', 'col4']
    }
  };

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

  return plugin;
};
RomeoAtoyann commented 2 months ago

Is this already resolved guys ?