verbb / cp-nav

Control Panel Nav is a Craft CMS plugin to help manage your Control Panel navigation.
MIT License
129 stars 11 forks source link

Export and import layouts #122

Closed marknotton closed 1 year ago

marknotton commented 1 year ago

What are you trying to do?

I'd like to carry over layout settings to multiple projects.

What's your proposed solution?

Add support via Crafts own configurations file.

It appears there is some logic in one of the migration files that refers to the config file already; however this doesn't do anything on fresh installations.

Strangely enough, when I asked ChatGTP about a way to accomplish this it made this suggestion:

In this example, the cp-nav.php configuration file contains a single navigation item with the label "My Custom Section". This item has a custom URL, a custom icon, a badge with a value of "1", and a custom attribute called data-my-custom-attribute with a value of my-custom-value. The item also has two child items, "Child 1" and "Child 2", which are displayed as sub-menu items when the parent item is clicked.

You can modify this example code to create your own custom navigation items for your Craft CMS control panel. You can also refer to the "CP Nav" plugin documentation for more information on how to configure the plugin settings in the cp-nav.php file.

return [
    'items' => [
        [
            'label' => 'My Custom Section',
            'url' => 'my-custom-section-url',
            'icon' => '@verbb/cp-nav/icon.svg',
            'badge' => '1',
            'badgeClass' => 'badge--new',
            'extraAttributes' => [
                'data-my-custom-attribute' => 'my-custom-value',
            ],
            'children' => [
                [
                    'label' => 'Child 1',
                    'url' => 'child-1-url',
                ],
                [
                    'label' => 'Child 2',
                    'url' => 'child-2-url',
                ],
            ],
        ],
    ],
];

I don't know if it made this up or has found reference to something online that I can't find. But it looks like a strong concept. If ChatGTP is referring to something that is "real" then perhaps this feature already exists and I just can't get it to work.

However, having found only one reference to querying the config file in the source code and this example coming from the imaginings of ChatGTP, I don't think this exists.

Additional context

No response

engram-design commented 1 year ago

Layouts are stored in the project config, so they can in theory be migrated from project to project via a YAML file. Using the config files like a plugin does is technically possible, but just double handling. So it's possible, there's just not a nice UI for import/export.

Appreciate the ChatGPT question, but that's entirely fictional and doesn't work. You best bet is to copy the YAML files from project config.

marknotton commented 1 year ago

I think for my purposes (and probably for most people), copying over the YAML files is all that's needed. I'm happy with this. Thanks!

ChatGTP making up plausible config suggestions is quite the testament for it can do; and reminder that it's just a language modal, not a "truth" machine.