How to add custom Admin Page to booty?

Post Reply
User avatar
SamBrishes
Ssr. Bludit
Posts: 13
Joined: Tue Dec 25, 2018 8:07 pm
Location: Austria 'n' Germany
Contact:

Thu Dec 27, 2018 11:53 am

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.
The cake isn't a lie, I just ate it.
» I'm a man of action. A swashbuckler. A rogue. A wanderer. A man who can hold his breath for ten minutes. « – Guybrush Threepwood, Monkey Island.
User avatar
Edi
Site Admin
Posts: 1405
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Contact:

Thu Dec 27, 2018 9:31 pm

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
Planet Bludit, Tipps, Snippets und nützliche Links. - Newsletter, Informationen zu Bludit (auf Deutsch).
User avatar
SamBrishes
Ssr. Bludit
Posts: 13
Joined: Tue Dec 25, 2018 8:07 pm
Location: Austria 'n' Germany
Contact:

Sat Dec 29, 2018 11:48 pm

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). ^^
The cake isn't a lie, I just ate it.
» I'm a man of action. A swashbuckler. A rogue. A wanderer. A man who can hold his breath for ten minutes. « – Guybrush Threepwood, Monkey Island.
User avatar
diego
Site Admin
Posts: 679
Joined: Sat May 16, 2015 2:53 pm
Contact:

Sun Dec 30, 2018 1:11 pm

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: 95
Joined: Wed Jun 07, 2017 1:05 pm
Contact:

Mon Dec 31, 2018 11:57 am

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 | check out startups undiluted - london's startup ecosystem
Post Reply