Jump to content

Admin Theme login screen


jploch
 Share

Recommended Posts

Hey folks,
Iam working on a new Admin Theme, based on AdminThemeReno, which I would like to release for the public soon.
Now I want to style the login page to fit the look and feel of the backend.

After some research, I found out that I have to set the "$config->defaultAdminTheme = 'AdminThemeName' " inside my site config.php file to load all the styles from my admin theme on the login page instead of the default ones.
Is it possible to set this via api from my Admin Theme settings, without the need of editing the config file?
 

Link to comment
Share on other sites

1 hour ago, jploch said:

Is it possible to set this via api from my Admin Theme settings, without the need of editing the config file?

Haven't done it myself, but I guess it should be possible. Have a look at AdminThemeUikit settings when editing it in Admin / Module /. You see this:

uikit-login-screen-settings.thumb.png.6d4ea9a7606f4ada396eed98fb309131.png

That shows it should be possible.

  • Like 2
Link to comment
Share on other sites

15 hours ago, kongondo said:

Haven't done it myself, but I guess it should be possible. Have a look at AdminThemeUikit settings when editing it in Admin / Module /. You see this:

Thx Kongondo! I already tried to find the code inside the AdminThemeUikit module files, but could not find this setting.
I will take another look and repost my findings 

Link to comment
Share on other sites

42 minutes ago, jploch said:

I will take another look and repost my findings 

Follow the rabbit from here: wire/core/AdminThemeFramework.php

/**
 * AdminTheme Framework
 * 
 * The methods in this class may eventually be merged to AdminTheme.php, 
 * but are isolated to this class during development. 
 *
 * @property bool $isSuperuser
 * @property bool $isEditor
 * @property bool $isLoggedIn
 * @property bool|string $isModal
 * @property bool|int $useAsLogin <------- this one?
 * @method array getUserNavArray()
 *
 */

$useAsLogin maybe?

Link to comment
Share on other sites

1 hour ago, kongondo said:

Follow the rabbit from here: wire/core/AdminThemeFramework.php

$useAsLogin maybe?

This seems to be it. The problem is that I don't know how to change that setting. My admin theme is based on reno and is not extending 'AdminThemeFramework' like the Uikit based themes, but the original 'AdminTheme'. So I could not integrate that setting in my theme.

I tried this in my theme (taken from AdminThemeFramework.php), wich resets the login settings on all the admin  themes, but then it switches back to AdminThemeUikit as the default:

$class = $this->className();
			foreach($this->modules->findByPrefix('AdminTheme') as $name) {
				if($name == $class) continue;
				$cfg = $this->modules->getConfig($name);
				if(!empty($cfg['useAsLogin'])) {
					unset($cfg['useAsLogin']);
					$this->modules->saveConfig($name, $cfg);
					$this->message("Removed 'useAsLogin' setting from $name", Notice::debug);
				}
			}

In the docs I found this:

AdminThemeFramework::useAsLogin

 

Link to comment
Share on other sites

I'll see if I can get time to have a play. From what I can tell, in AdminThemeFramework::init we have this code:

<?php namespace ProcessWire;
$user = $this->wire('user');
if(!$user->isLoggedin() && $this->useAsLogin) $this->setCurrent();
parent::init();

That checks if the user is NOT logged in and if useAsLogin is true...

$this->setCurrent() is a method in the base class, AdminTheme. Like you said, $useAsLogin is native to AdminThemeFramework. However, AdminThemeFramework only uses it internally to see if to use setCurrent().

In AdminTheme::init, it will first check if there is a user specified theme and if that matches the current admin theme. If true, it will use setCurrent() to set it as the current theme. Else, it will fall back to what is specified in $config->defaultAdminTheme, if a value exists there.

<?php namespace ProcessWire;
if($adminTheme) {
// there is user specified admin theme
// check if this is the one that should be used
if($adminTheme == $this->className()) $this->setCurrent();

} else if($this->wire('config')->defaultAdminTheme == $this->className()) {
// there is no user specified admin theme, so use this one
$this->setCurrent();
}

I am guessing that in the init() method of your custom AdminTheme, you can use the above logic (first code) similar to what is in AdminThemeFrameWork::init (the bit about user not logged in....).

Sorry if this doesn't make sense; Written in a hurry...

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

@kongondo Thanks! This worked very well. With your help I implemented a setting to use my admin theme for the login. It works only if I also set the guest user to use my admin theme. This needs to be done manually in the profile settings, in addition to the module settings. For better usabillity it would be nice to set the guest user admin theme via api as well. I know that "$user->admin_theme" gives me the name for the admin theme of the current user but I have no Idea how to set the theme for the guest user. Any ideas?

Link to comment
Share on other sites

1 hour ago, jploch said:

This worked very well.

Glad you got it sorted! 😄.

1 hour ago, jploch said:

It works only if I also set the guest user to use my admin theme. This needs to be done manually in the profile settings, in addition to the module settings.

Hmm. That sounds like one-too-many hoops.

1 hour ago, jploch said:

For better usabillity it would be nice to set the guest user admin theme via api as well. I know that "$user->admin_theme" gives me the name for the admin theme of the current user but I have no Idea how to set the theme for the guest user. Any ideas?

This is an interesting one. I have never really thought of the guest needing to have a preferred theme, but I can see the setting in Users > guest. Why would the guest need a theme at all?

I'll have a think unless someone beats me to this.

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

×
×
  • Create New...