Jump to content

Modifying logo in admin theme


MarkE
 Share

Recommended Posts

The standard admin themes (UI, Rock etc) permit you to modify the logo by giving a path to it. I would like to be able to specify the logo as being an image field on a settings page? I know I could do this with a fairly ugly hack using regex in a hook on Page::render, but I wonder if there is a better way?

Link to comment
Share on other sites

You could create a template and page to output the settings page image and specify that URL in the theme setting.

Simplification: if your settings page doesn't have a PHP template yet, you could use that one, or you could extend the existing one. With url segments, you could even pull different stuff from it (logo image, icons, disclaimer, ...).

Code for settings template:

<?php namespace ProcessWire;

if($input->urlSegment(1) === 'logo') {
	wireSendFile($page->logoimage->filename, [
		'exit'		=>	true
	]);
}

Then just put /path/to/settings/page/logo/ into the logo image file field.

  • Like 7
Link to comment
Share on other sites

8 hours ago, MarkE said:

The standard admin themes (UI, Rock etc) permit you to modify the logo by giving a path to it. I would like to be able to specify the logo as being an image field on a settings page? I know I could do this with a fairly ugly hack using regex in a hook on Page::render, but I wonder if there is a better way?

That's always a little annoying for me as well. What if AdminStyleRock created a logo field for you and placed it on the home template? Would that be what you want? You could then also move it to your dedicated settings page.

Link to comment
Share on other sites

16 hours ago, MarkE said:

The standard admin themes (UI, Rock etc) permit you to modify the logo by giving a path to it. I would like to be able to specify the logo as being an image field on a settings page? I know I could do this with a fairly ugly hack using regex in a hook on Page::render, but I wonder if there is a better way?

I don't know if my way is better, but for me it has become standard ?

This is easy done:

I set the imagepath in AdminTheme to: '/site/assets/files/1020/be-logo.svg' (1020 is my settingspage) and to make sure that the image name is always the same I use the Custom Upload Names module. Now I can simply upload a new logo and have it available in the backend.

I exported this configuration with some fields and settings that I need again and again with the Profile Exporter from @ryan and use this as a starting point for almost every new installation.

Link to comment
Share on other sites

1 hour ago, Markus Thomas said:

I set the imagepath in AdminTheme to: '/site/assets/files/1020/be-logo.svg' (1020 is my settingspage)

I did think of that, but with multiple installations I am not confident that the id of the settings page will be identical. Maybe I’m just being overly cautious. 

Link to comment
Share on other sites

1 hour ago, MarkE said:

I did think of that, but with multiple installations I am not confident that the id of the settings page will be identical. Maybe I’m just being overly cautious. 

I can understand that, for me it's just always the same ID.

Alternatively, you can also overwrite the LogoURL in admin.php.
Directly before:

require($config->paths->adminTemplates . 'controller.php');

with:

$adminTheme->logoURL = $mylogourl

I use this for multisites where I need different logos depending on the URL.

  • Like 2
Link to comment
Share on other sites

That's great @Markus Thomas. The only slight disadvantage is that it may not be obvious to the website manager that setting the logo in the Uikit admin settings has no effect. So what I did was entered 'not_used_Overriden_in_admin.php' in the logo image file field.

  • Like 1
Link to comment
Share on other sites

12 hours ago, BitPoet said:

Code for settings template:

<?php namespace ProcessWire;

if($input->urlSegment(1) === 'logo') {
	wireSendFile($page->logoimage->filename, [
		'exit'		=>	true
	]);
}

Then just put /path/to/settings/page/logo/ into the logo image file field.

That's a really neat trick - useful in a bunch of other contexts too!

So 2 great solutions from @BitPoet and @Markus Thomas - spoilt for choice (and I will get back to @bernhard with ideas too). ?

Link to comment
Share on other sites

14 hours ago, bernhard said:

What if AdminStyleRock created a logo field for you and placed it on the home template? Would that be what you want? You could then also move it to your dedicated settings page.

Interesting thought. I'm not too keen personally on modules modifying the database in this way. Another approach would be to have a page ref field and a field with the name of the image field. That said, the solutions suggested above work well anyway. Having tried both of them I am marginally inclined towards @BitPoet's solution as the entry in the module settings is clear and it seems a bit more 'Processwiry'.

Link to comment
Share on other sites

1 hour ago, bernhard said:

I'd be interested what you mean exactly by "in this way"? Can you please describe this in more detail?

I mean adding a field to a pre-existing template. My preferred approach is that modules may add templates and fields, but not automatically modify existing ones - that should be left to the webmaster or superuser, whether directly via setup or via module settings. Also, any new templates and fields should have names that are unlikely to conflict, e.g. by using an appropriate prefix. 

Link to comment
Share on other sites

4 hours ago, MarkE said:

I mean adding a field to a pre-existing template. My preferred approach is that modules may add templates and fields, but not automatically modify existing ones - that should be left to the webmaster or superuser, whether directly via setup or via module settings. Also, any new templates and fields should have names that are unlikely to conflict, e.g. by using an appropriate prefix. 

Yeah, understand that. That's why RockFrontend does it only if you check a box:

IHrAzez.png

And I'm also using prefixes to avoid naming collisions. So for example the favicon field's name is "rockfrontend_favicon".

For AdminStyleRock I decided to go a little different route. The field is automatically added to the home template, but it will be hidden unless you are a superuser and really request the field to be visible with an url parameter. The field's name is adminstylerock_adminlogo.

I've just pushed that update to the AdminStyleRock dev branch that replaces the old logo-url-inputfield with a new upload field ? 

6LjFpIf.png

  • Like 2
Link to comment
Share on other sites

Thanks @bernhard  I use RockFrontend and am fairly happy with that approach, although I would prefer to say which template to add, for example, favicon to (e.g. my settings template). 
Re the new logo field. Would that be accessible elsewhere in the API? I sometimes use the logo in other places than just the admin masthead. 

Link to comment
Share on other sites

26 minutes ago, MarkE said:

Thanks @bernhard  I use RockFrontend and am fairly happy with that approach, although I would prefer to say which template to add, for example, favicon to (e.g. my settings template). 

Yeah, that should also be no problem. It just makes things more complicated and takes longer to develop. But if anybody has a need for something I'm happy to accept PRs or custom support requests.

29 minutes ago, MarkE said:

Re the new logo field. Would that be accessible elsewhere in the API? I sometimes use the logo in other places than just the admin masthead.

Sure! I added a comment to make that more obvious:

Quote

You want to use the logo somewhere else? Use $pages->get(1)->adminstylerock_adminlogo to get the PageImage object that you can resize etc.

  • Like 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...