Universeorange.com/Docs/

R3m/framework Add a custom plugin

At using plugins we defined menu.get().
First we set the environment to development.

<name> configure environment toggle

<name> the binary name of R3m/framework (see installation).
It says Production mode enabled. or Development mode enabled..
We need Development mode enabled..

If we navigate to http://<subdomain>.<hostname>.<extension>/Docs/Welcome/ you will get: PluginNotFoundException Function not found with an array:
It expects the plugin menu.get() to be defined in one of these directories.

array(4) {
  [0]=> "<project_dir>/Host/<subdomain>/<hostname>/<extension>/Docs/Plugin/",
  [1]=> "<project_dir>/Host/<subdomain>/<hostname>/<extension>/Plugin/",
  [2]=> "<project_dir>/src/Plugin/",
  [3]=> "<project_dir>/vendor/r3m/framework/src/Plugin/"
}

We create a file <project_dir>/Host/<subdomain>/<hostname>/<extension>/Docs/Plugin/Function_menu_get.php.
In that file:

<?php
/**
 * @author          Remco van der Velde
 * @since           2020-09-13
 * @copyright       Remco van der Velde
 * @license         MIT
 * @version         1.0
 * @changeLog
 *     -            all
 */
use stdClass;
use R3m\Io\Module\Parse;
use R3m\Io\Module\Data;

function function_menu_get(Parse $parse, Data $data, $page=''){
    $object = $parse->object();
    $options = [];    
    $options['page'] = $page;    
    /**
     *  Going to the model to handle the menu result.
     */
    return \Host\<subdomain>\<domain>\<extension>\Docs\Model\Menu::get(
        $object,
        $options
    );
}

Model

We create a file <project_dir>/Host/<subdomain>/<hostname>/<extension>/Docs/Model/Menu.php.

With the following content:

<?php

namespace Host\<subdomain>\<hostname\<extension>\Docs\Model;

use R3m\Io\App;

class Menu {

    public static function get(App $object, $options=[]){
        $url = $object->config('controller.dir.data') . 'Menu' . $object->config('extension.json');
        $data = $object->parse_read($url);        
        if($data){        
            $result = [];
            $result[] = '<ul class="menu">';
            $menu =  $data->data('menu');
            foreach($menu as $item){
                if(property_exists('html', $item)){                
                    $result[] = $item.html;
                }
            }
            $result[] = '</ul>';
            return implode("\n", $result);
        }
        return '';
    }        
}

The .json data file located: project_dir\Host\<subdomain>\<hostname>\<extension>\Data\Menu.json:

{
    "menu" : [
        {
            "name" : "...",
            "class" : "{menu.class($this.name)}",
            "title" : "{$this.name}",
            "page" : "{$this.name}",
            "href" : "{route.get('<subdomain>-<hostname>-<extension>-docs-page', ['page' => $this.page])}",
            "html" : "<a href=\"{$this.href}\" class=\"{$this.class}\" title=\"{$this.title}\"><li>{$this.name}</li></a>"
        },
        ...
    ]
}   

Due to the method $object->parse_read() in the model, plugins and $this are available in the .json document.

Last modified: 2021-06-07

© 2021 universeorange.com