rainlab / pages-plugin

Adds static pages and menus
MIT License
122 stars 99 forks source link

Custom Types missing from menu after v1 - v2 upgrade #507

Closed spacebeers closed 2 years ago

spacebeers commented 2 years ago

Description:

I've recently managed to upgrade a mess of an October CMS site to v2 and I've got one last issue before I can release it.

The Pages plugin menu builder won't recognise my types created in the Builder plugin anymore. The UI only shows the standard list of types since the upgrade.

Screenshot 2022-08-12 at 15 05 09 Screenshot 2022-08-12 at 15 05 28

If it's any help I've also lost all my menu styling classes from the mark up now too.

My familiarity with the October ecosystem isn't great so any pointing in the right direction would be great.

daftspunk commented 2 years ago

No worries, can you share the code that you are using to extend the types?

spacebeers commented 2 years ago

@daftspunk So the site's all made using the builder so I've got no idea where to look for that. Any clues very welcome

daftspunk commented 2 years ago

Alright, can you walk me through the steps you took using Builder to arrive at this point? It will help to recreate the problem on our end.

spacebeers commented 2 years ago

Thanks. I've worked part of it out and that's mainly that the previous developer had changed the following inside the plugin:

This had been changed to include the Bootstrap menu classes so that's one mystery solved.

spacebeers commented 2 years ago

As for the rest of it - all I've done is upgraded October core and then the plugins. This wiped out the styling as mentioned about but in the admin I still get the "Undefined index: discover" on line 113 when trying to update the menu.

There are two types from Builder that I assume were appearing in the Types dropdown previously (Discover and Product). Is there any documentation on how to add types to the dropdown?

daftspunk commented 2 years ago

Ok, modifying core files will have this effect. Here is the docs on registering custom menu types (Discover and Product):


Creating new menu item types

Plugins can extend the Static Pages plugin with new menu item types. Please refer to the Blog plugin for the integration example. New item types are registered with the API events triggered by the Static Pages plugin. The event handlers should be defined in the boot() method of the plugin registration file. There are three events that should be handled in the plugin.

The next example shows an event handler registration code for the Blog plugin. The Blog plugin registers two item types. As you can see, the Blog plugin uses the Category class to handle the events. That's a recommended approach.

public function boot()
{
    Event::listen('pages.menuitem.listTypes', function() {
        return [
            'blog-category'=>'Blog category',
            'all-blog-categories'=>'All blog categories',
        ];
    });

    Event::listen('pages.menuitem.getTypeInfo', function($type) {
        if ($type == 'blog-category' || $type == 'all-blog-categories') {
            return Category::getMenuTypeInfo($type);
        }
    });

    Event::listen('pages.menuitem.resolveItem', function($type, $item, $url, $theme) {
        if ($type == 'blog-category' || $type == 'all-blog-categories') {
            return Category::resolveMenuItem($item, $url, $theme);
        }
    });
}
spacebeers commented 2 years ago

Looks like they were just updating the core files! No wonder I couldn't find it. Thanks so much for your help.

Screenshot 2022-08-19 at 07 39 56