Creating Backend Pages

Hello there,

I’m trying to set up a custom page inside the admin plugin. I want to create a custom configuration page for my plugin, because there can be a lot of data to add and edit, so it seemed to me pretty cray to add all these stuff inside the standard configuration.

I already set up a custom menu page, that calls a certain page. But how can I use kind somekind of blueprint-form on this page, that saves the entered/edited content to some custom yaml files inside the user/data directory?

I would be great if somebody could give me a quick rundown on how to do this.

Thanks and regards,
Michael

The PHP file comments.php from the ‘comments’ plugin shows how to save/retrieve data to/from the ‘user/data’ folder.

Thank you @pamtbaau, but I don’t see how to handle the data the same way they can handeld by the admin plugin for example.

What is it you are missing?

Hard to explain. I wanted to rebuild the same functionality like you have when using blueprints in backend. This more like adding single files without any abillity to edit or replace data.

I thought of using the class \Grav\Common\Data\Blueprint, but I don’t know how.

Soooo, i solved the problem on storing data (using the “Blueprint”-Class. Here is the way I use to store YAML-Files.

<?php
namespace Grav\Plugin;

use Grav\Common\Plugin;
//...
use Grav\Common\Data;
use Grav\Common\File\CompiledYamlFile;


class ExamplePlugin extends Plugin
{

     /**
     * @var Data\Blueprints
     */
    protected $blueprints;


    //...
    public function storeData(){
          //set up Blueprints class with place where to look for blueprints
          if ($this->blueprints === null) {
             $this->blueprints = new Data\Blueprints('blueprints://');
           }

          //createt a blueprints folder inside the plugin and example-file "blueprinttype.yaml"
          //Create new Data-object with collected Blueprint-Object
          $data = new Data\Data(["example"=> true],$this->blueprints->get('blueprinttype'));
          //find/create storage file
          $file = CompiledYamlFile::instance($this->grav['locator']->findResource('user://data/example/config' . YAML_EXT,
                    true, true));
    }
            
              //attach storage file to Data-object and save 
               $data->file($file);
               $data->save();



}

After saving $data->save(); the data are stored in the given file. Awesome!
But now I don’t know how to build a form out of the blueprint.

Regards,
Michael