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?
It’s a pretty simple process to extend an existing page form. Or even add a simple ‘configuration’ form (like that for
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:
The comments plugin: https://github.com/getgrav/grav-plugin-comments - this doesn’t actually have a form, it does have a
.mdpage that it uses for authorization, and an associated Twig template to render a list of comments.
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:
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.
Thank you, I will try to piece something together while I await the documentation/.framework
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.
That’s definitely a simpler process.
create a plugin that contains a
blueprints/config/site.yamlfile. This file should either replace the existing
system/blueprints/config/site.yamlor extend it. - see docs on that.
in your plugin’s PHP, add this code at the top of the class:
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.
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.
Thanks @rhukster, I will give that a go!
I did some exploring @rhukster and I found that I could do what I wanted to do sans-plugin: https://learn.getgrav.org/forms/blueprints/example-config-blueprints
Very good instructions on that page, and here is the proof
Thanks again for the help!
If anyone is looking for a working example to go along with the above article on the learn.getgrav.org site you can view my extended site.yaml file on GitHub: https://raw.githubusercontent.com/hibbitts-design/grav-skeleton-course-hub/master/blueprints/config/site.yaml