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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Creating Backend Pages

admin plugins

Started by Michael Gollmer 8 years ago · 5 replies · 858 views
8 years ago

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

8 years ago

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

8 years ago

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.

8 years ago

What is it you are missing?

8 years ago

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.

8 years ago

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

PHP
<?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

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 47 1 week ago
Plugins · by Xavier, 4 weeks ago
2 56 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1182 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 50 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 74 2 months ago