Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Add custom form in Admin Panel

Started by Muut Archive 10 years ago · 8 replies · 1223 views
10 years ago

Hello, I have created a Grav plugin and created a page in the Admin panel for the plugin. However, I can not figure out how to add a form to my admin page. Does anyone have any insight on how I can accomplish this?

10 years ago

It's a pretty simple process to extend an existing page form. Or even add a simple 'configuration' form (like that for system/config/site.yaml).

However, if you want to create a completely custom 'section' of the admin with it's own form storing it's own data and doing it's own thing, that's quite a bit more involved. I really need to do an in-depth tutorial on this because it's not so trivial I can outline it in a forum post.

I would suggest in the meantime to checkout a couple of plugins:

  1. The comments plugin: https://github.com/getgrav/grav-plugin-comments - this doesn't actually have a form, it does have a .md page that it uses for authorization, and an associated Twig template to render a list of comments.

  2. The admin plugin itself: https://github.com/getgrav/grav-plugin-admin - This has several places where a form is built from a blueprint. That's mainly done with this command:

https://github.com/getgrav/grav-plugin-admin/blob/develop/themes/grav/templates/config.html.twig#L80

This is where you pass the blueprint data to the partials/blueprints.htm l.twig to render out the form.

Then you need to have a task or method to validate and save the values.

This whole process is something we plan on providing some better 'framework' to handle going forward. For now it's possible, but requires quite a bit of development. Luckily all the code you need is contained within existing plugins.

10 years ago

Thank you, I will try to piece something together while I await the documentation/.framework

10 years ago

This is a very helpful discussion, as in fact I am right now trying to figure out how to make additional fields in the user/config/site.yaml file easily editable via the Admin Panel.

What might be the starting point to do that?

Thanks very much.

10 years ago

That's definitely a simpler process.

1) create a plugin that contains a blueprints/config/site.yaml file. This file should either replace the existing system/blueprints/config/site.yaml or extend it. - see docs on that.

2) in your plugin's PHP, add this code at the top of the class:

PHP
    public $features = [
        'blueprints' => 1000,
    ];

I think that will do it! if that doesn't work, you might need to add one more bit, but i'm not convinced it's required for site.yaml tweaks.

10 years ago

How do I pass in my blueprint to the the blueprints partial? I have a YAML file containing the form, but I am unsure how to pass it in.

10 years ago

Thanks @rhukster, I will give that a go!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1328 9 years ago
Archive · by Muut Archive, 9 years ago
2 921 9 years ago
Archive · by Muut Archive, 9 years ago
2 4050 9 years ago
Archive · by Muut Archive, 9 years ago
1 2928 9 years ago
Archive · by Muut Archive, 9 years ago
3 1107 9 years ago