Jump to content

Add Helper.php file to Uikit Admin Theme, to allow hooks


Federico
 Share

Recommended Posts

Hello pw community,

is it possible to add some hook functions to the Uikit theme as well? I see all others themes (default and Reno) have extensive hooks capabilities, whereas the Uikit based theme in the admin has only the ___breadcrumb available. I am looking specifically to hook the masterhead navigation, but I believe the array of requests might be larger. I was discussing this on another thread

@ryan sorry to bother you, maybe you already gave it some thoughts about. Do you think this will require intense work?

Thank you very much!

Link to comment
Share on other sites

hi federico, sorry for you that you didn't get any answers so far. the community is usually really fast and helpful ;)

Unfortunately I cannot help you with your question, but maybe it's worth looking at the AdminOnSteroids module. tpr does a lot of adjustments there - so it should be definitely possible to adopt the themes to your needs.

Maybe you can elaborate your case more in detail and get better answers :)

Link to comment
Share on other sites

Hi @bernhard, my use case is to find this type of hook for the main navigation and prepend or append something to it. In Reno Admin theme (but also in the default admin theme too) we could achieve this with the following code

$wire->addHookAfter('AdminThemeRenoHelpers::topNavItems', function($event) {
  $out = $event->return;
  $out .= '<li><img src="path/image.png"></li>';
  $event->return = $out;
});

Whereas you cannot leverage a similar hook to the Uikit theme (the latter soon to be the default theme). Am I correct?

  • Like 1
Link to comment
Share on other sites

i have a request in also to add hook to UI Kit theme, especially for being able to manipulate css files; i was able to sort out my issue (FontAwesomePro module) using another way, but i do think it is important to add api hooks in key/strategic areas on the admin themes, for customization.

https://github.com/processwire/processwire-requests/issues/120

  • Like 4
Link to comment
Share on other sites

In terms of adding markup to admin themes, the following hookable methods are common to all admin themes:

AdminThemeFramework::getUserNavArray

Allows you to add items to or remove items from the "user" dropdown menu (Edit Profile, etc).

AdminTheme::getExtraMarkup

Allows you to add markup to the following regions of the admin template:

  • head
  • notices
  • body
  • masthead
  • content
  • footer
  • sidebar 

For example...

$wire->addHookAfter('AdminTheme::getExtraMarkup', function(HookEvent $event) {
    $regions = $event->return;
    $regions['masthead'] .= '<p>hello</p>';
    $event->return = $regions;
});

So not every place in the admin theme markup is covered (I don't see how it could be), but it allows for simple additions to the admin theme. No doubt you would need some custom admin CSS to position and style whatever markup you add.

 

Other approaches...

Manipulate the rendered markup string

For some cases this might do the job. For example...

$wire->addHookAfter('Page::render', function(HookEvent $event) {
    $page = $event->object;
    if($page->template == 'admin') {
        $out = $event->return;
        $out = str_replace('<div class="uk-navbar-right">', '<div class="uk-navbar-right"><p>hello</p>', $out);
        $event->return = $out;
    }
});

 

Copy your preferred admin theme module from /wire/modules/AdminTheme/ to /site/modules/

Make whatever changes you need to the copied files, perhaps by including a separate PHP file at the right place in the template markup. That will make it easier to update the admin theme module from the core version when you choose to.

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...