Giter Site home page Giter Site logo

wn-nexus-plugin's Introduction

Xitara Nexus Plugin devDependency Status Known Vulnerabilities

Implements backend sidemenu, custom menus, menu sorting

Getting started

  • clone the repo to folder plugins/xitara/nexus
  • cd to plugins/xitara/nexus
  • run yarn to fetch all the dependencies

Commands

  • start - start the dev server
  • cleanup - remove compiled data, node_modules, vendor, etc. don't delete any sources
  • watch - start webpack --watch
  • dwatch - start webpack --watch --mode development
  • build - build the complete app including copying static content
  • dbuild - build the complete app including copying static content with --mode development
  • zip - zips a package with only needed files without overhead
  • deploy - deploys a package with only needed files without overhead in a folder without zipping
  • ftp - uploads a minimizes package to a configured server (needs lftp)
  • analyze - analyze your production bundle
  • lint-code - run an ESLint check
  • lint-style - run a Stylelint check
  • check-eslint-config - check if ESLint config contains any rules that are unnecessary or conflict with Prettier
  • check-stylelint-config - check if Stylelint config contains any rules that are unnecessary or conflict with Prettier

Register new Plugin to Sidemenu

Add on top of Plugin.php

use App;
use Backend;
use BackendMenu;
use Event;
use System\Classes\PluginBase;
use System\Classes\PluginManager;

Add to boot() method to catch event and display new sidemenu.

/**
 * Check if we are currently in backend module.
 */
if (!App::runningInBackend()) {
    return;
}

/**
 * get sidemenu if nexus-plugin is loaded
 */
if (PluginManager::instance()->exists('Xitara.Nexus') === true) {
    Event::listen('backend.page.beforeDisplay', function ($controller, $action, $params) {
        $namespace = (new \ReflectionObject($controller))->getNamespaceName();

        if ($namespace == '[VENDOR]\[PLUGIN]\Controllers') {
            \Xitara\Nexus\Plugin::getSideMenu('[VENDOR].[PLUGIN]', '[PLUGIN-SLUG]');
        }
    });
}

Register sidemenu partial

public function register()
{
    if (PluginManager::instance()->exists('Xitara.Nexus') === true) {
        BackendMenu::registerContextSidenavPartial(
            '[VENDOR].[PLUGIN]',
            '[PLUGIN-SLUG]',
            '$/xitara/nexus/partials/_sidebar.htm'
        );
    }
    // ...
}

Extend your navigation label with ::hidden to hide it from top navigation

public function registerNavigation()
{
    $label = '[VENDOR-SLUG].[PLUGIN-SLUG]::lang.plugin.name';

    if (PluginManager::instance()->exists('Xitara.Nexus') === true) {
        $label .= '::hidden';
    }

    return [
        '[PLUGIN-SLUG]' => [
            'label' => $label,
            'url' => Backend::url('[VENDOR-SLUG]/[PLUGIN-SLUG]/[CONTROLLER-SLUG]'),
            'icon' => 'icon-leaf',
            'permissions' => ['[VENDOR-SLUG].[PLUGIN-SLUG].*'],
            'order' => 500,
        ],
    ];
}

Inject menu items

public static function injectSideMenu()
{
    $i = 0;
    return [
        '[PLUGIN-SLUG].[CONTROLLER-SLUG]' => [
            'label' => '[VENDOR-SLUG].[PLUGIN-SLUG]::lang.submenu.[CONTROLLER-SLUG]',
            'url' => Backend::url('[VENDOR-SLUG]/[PLUGIN-SLUG]/[CONTROLLER-SLUG]'),
            'icon' => 'icon-archive',
            'permissions' => ['[VENDOR-SLUG].[PLUGIN-SLUG].*'],
            'attributes' => [ // can be extendet if you need, no limitations
                'group' => '[VENDOR-SLUG].[PLUGIN-SLUG]::lang.submenu.label',
                'level' => 1, // optional, default is level 0. adds css-class level-X to li
            ],
            'order' => \Xitara\Nexus\Plugin::getMenuOrder('[VENDOR-SLUG].[PLUGIN-SLUG]') + $i++,
        ],
        ...
    ];
}

Set backend menu context in controller

public function __construct()
{
    parent::__construct();
    BackendMenu::setContext('[VENDOR].[PLUGIN]', '[PLUGIN-SLUG]', 'nexus.[CONTROLLER-SLUG]');
}

Translation

  • [VENDOR-SLUG].[PLUGIN-SLUG]::lang.submenu.label is the heading of your menu items
  • [VENDOR-SLUG].[PLUGIN-SLUG]::lang.submenu.[CONTROLLER] is the your menu item

Register backend settings

You must implement your own settings model in your plugin

On top of Plugin.php:

use Xitara\Nexus\Models\Setting;

and as registration method

public function registerSettings()
{
    if (($category = Settings::get('menu_text')) == '') {
        $category = 'xitara.nexus::core.setting.name';
    }

    return [
        'settings' => [
            'category' => $category,
            'label' => '[VENDOR_SLUG].[PLUGIN_SLUG]::lang.submenu.label',
            'description' => '[VENDOR_SLUG].[PLUGIN_SLUG]::lang.submenu.description',
            'icon' => 'icon-comments-o',
            'class' => '[VENDOR]\[PLUGIN]\Models\Settings',
            'order' => 20,
        ],
    ];
}

wn-nexus-plugin's People

Contributors

xitara avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.