How to add custom Admin Page to booty?

Post Reply
SamBrishes
Master Bludit
Posts: 106
Joined: Tue Dec 25, 2018 8:07 pm
Been thanked: 3 times

Hellow,

is there any supported way to add custom admin pages (or views) from a plugin to the default booty admin theme (next to the "plugin configuration" pages)?

I couldn't found a working solution, and it seems impossible due to the "Sanitize::pathFile" check, which prevents Symbolic links. (So at least it doesn't work by changing the global "$layout" variable using the "beforeAdminLoad" hook.).

My current solution uses a regular expression to inject my own admin page:

Code: Select all

<?php
class MyPlugin extends Plugin{

    /*
     |  HOOK :: ADD PAGE TO ADMIN SIDEBAR
     |  @since  0.1.0
     */
    public function adminSidebar(){
        return '<a href="' . HTML_PATH_ADMIN_ROOT . 'my-admin-page">My Admin Page</a>';
    }

    /*
     |  HOOK :: BEFORE ADMIN CONTENT
     */
    public function adminBodyBegin(){
        if(!$this->isMyAdmin){
            // The current view isn't my plugin admin page
            return false;
        }
        ob_start();
    }

    /*
     |  HOOK :: AFTER ADMIN CONTENT
     */
    public function adminBodyEnd(){
        if(!$this->isMyAdmin){
            // The current view isn't my plugin admin page
            return false;
        }
        $content = ob_get_contents();
        ob_end_clean();
    
        // Load my AdminPage
        ob_start();
        include("system/admin.php");
        $add = ob_get_contents();
        ob_end_clean();

        // Inject Code
        $regexp = "#(\<div class=\"col-lg-10 pt-3 pb-1 h-100\"\>)(.*?)(\<\/div\>)#s";
        $content = preg_replace($regexp, "$1{$add}$3", $content);
        print($content);
    }
}
?>
Thanks in advance.

Sincerely,
Sam.
User avatar
Edi
Site Admin
Posts: 3120
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

What is the idea of a custom admin page?

You can code a custom theme and use the following hooks:
  • adminHead
  • adminBodyBegin
  • adminBodyEnd
  • adminSidebar
A list of all hooks can be found in the documentation:

https://docs.bludit.com/en/plugins/hooks-list
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
SamBrishes
Master Bludit
Posts: 106
Joined: Tue Dec 25, 2018 8:07 pm
Been thanked: 3 times

Hellow,

the idea was to extend the Bludit System with additional functions and features, which integrates itself seamless to the Bludit backend. For example: I wrote a small plugin, which offers a "theme environment" (as shown here and on this tweet) and I found the administration hook "adminSidebar" which allows to add additional sidebar links. But I didn't found a official solution to "route" (or map) this links to a custom view / a custom admin page.

So I didn't want to write a full admin theme, I just want to implement one or two additional pages to the existing one. The only supported solution I found to extend the administration was the "form()" method on the respective Plugin class. (Which doesn't work, because this method gets called within a "<form>" element.)

Sincerely,
Sam.

PS.: I didn't know, that a official core theme environment is currently already in work as I started this experiment (So the plugin mentioned above won't get published). ^^
User avatar
diego
Site Admin
Posts: 773
Joined: Sat May 16, 2015 2:53 pm
Been thanked: 1 time
Contact:

Hi,
the admin panel is not so flexible, just in the version 3.x included the sidebar hook.

You can create a controller and a view.
/bl-kernel/admin/controller/test.php
/bl-kernel/admin/view/test.php

Then you can call like this
https://example.com/admin/test

The only problem I see here is to include the link in the sidebar, you need a plugin for that.
User avatar
bayerberg
Master Bludit
Posts: 139
Joined: Wed Jun 07, 2017 1:05 pm
Location: London, UK
Has thanked: 7 times
Been thanked: 10 times
Contact:

BTW would be nice to have admin area less dependent on bootstrap. I did my own version of an admin theme but had to do extra work to work around styling and js that bootstrap provides. I use things like sass version of http://getskeleton.com/ (less crap :) ), if admin area would be cleaner it would be easier to integrate plugins that add custom fields, integrate with services available..
bludit plugins and themes - makeitblu | I do things, check them out on behance and dribbble.
Post Reply