server icon indicating copy to clipboard operation
server copied to clipboard

[Bug]: unable to change login title via themes/../defaults.php

Open mrAceT opened this issue 1 year ago • 13 comments

⚠️ This issue respects the following points: ⚠️

Bug description

I am working creating a different theme for a client, using the same NexCloud instance.

All is going nicely, but I can't get the name altered visible in the Login-screen.. I've got all the rest!

Is it a bug or did I miss a variable?

Steps to reproduce

  1. create a custom theme
  2. and alter all the possible titles
  3. still no title change in the login screen

Expected behavior

A way to change that title also via defaults.php

Installation method

None

Nextcloud Server version

27

Operating system

None

PHP engine version

None

Web server

None

Database engine version

None

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

  • [ ] Default user-backend (database)
  • [ ] LDAP/ Active Directory
  • [ ] SSO - SAML
  • [ ] Other

Configuration report

No response

List of activated Apps

No response

Nextcloud Signing status

No response

Nextcloud Logs

No response

Additional info

image

I've set all these "title options" I could find.. and all are changed.. except this one!

This is my defaults.php:

class OC_Theme {

	/**
	 * Returns the base URL
	 * @return string URL
	 */
	public function getBaseUrl() {
		return 'https://alt.url;
	}

	/**
	 * Returns the documentation URL
	 * @return string URL
	 */
	public function getDocBaseUrl() {
		return 'https://alt.url';
	}

	/**
	 * Returns the title
	 * @return string title
	 */
	public function getTitle() {
		return 'alt title';
	}

	/**
	 * Returns the short name of the software
	 * @return string title
	 */
	public function getName() {
		return 'alt title';
	}

	/**
	 * Returns the short name of the software containing HTML strings
	 * @return string title
	 */
	public function getHTMLName() {
		return 'alt title';
	}

	/**
	 * Returns entity (e.g. company name) - used for footer, copyright
	 * @return string entity name
	 */
	public function getEntity() {
		return 'alt title';
	}

	/**
	 * Returns slogan
	 * @return string slogan
	 */
	public function getSlogan() {
		return 'alt slogan!';
	}

	/**
	 * Returns short version of the footer
	 * @return string short footer
	 */
	public function getShortFooter() {
		$footer = '© ' . date('Y') . ' <a href="' . $this->getBaseUrl() . '" target="_blank">' . $this->getEntity() . '</a>' .
			'<br/>' . $this->getSlogan();

		return $footer;
	}

	/**
	 * Returns long version of the footer
	 * @return string long footer
	 */
	public function getLongFooter() {
		$footer = '© ' . date('Y') . ' <a href="' . $this->getBaseUrl() . '" target="_blank">' . $this->getEntity() . '</a>' .
			'<br/>' . $this->getSlogan();

		return $footer;
	}

	/**
	 * Generate a documentation link for a given key
	 * @return string documentation link
	 */
	public function buildDocLinkToKey($key) {
		return $this->getDocBaseUrl() . '/server/15/go.php?to=' . $key;
	}


	/**
	 * Returns mail header color
	 * @return string
	 */
	public function getColorPrimary() {
		return '#87593D';
	}

	/**
	 * Returns variables to overload defaults from core/css/variables.scss
	 * @return array
	 */
	public function getScssVariables() {
		return [
			'color-primary' => '#87593D',
			'color-primary-light' => '#C69F89',
      'image-background'=> '/themes/../core/img/alt.bg.img',
		];
	}
}

mrAceT avatar Jun 27 '24 12:06 mrAceT

https://github.com/nextcloud/server/blob/d2249148e7231497598b0a6b99233477aa14ac9e/core/src/components/login/LoginForm.vue#L185

I expect the name should be used there but haven't tested it.

kesselb avatar Jun 27 '24 12:06 kesselb

I expect there to be some more logic in het part below where the slogan is shown.. that part goes as expected.. (?)

That gets altered via 'public function getSlogan'

mrAceT avatar Jun 27 '24 13:06 mrAceT

The assignment to OC.theme.name is done here:

https://github.com/nextcloud/server/blob/00aa8f543841c6bfd853a3ac5cb4ff3ab0a058ae/lib/private/Template/JSConfigHelper.php#L242

A starting point for you could be to inspect OC.theme in your browser's console and see if that has the right value.

kesselb avatar Jun 27 '24 13:06 kesselb

There it gets a bit messy? OC.theme.slogan has the 'standard slogan' I've set in the main config (log in as admin and change/set the values in the web-admin-panel)

But the slogan I see in the theme-login is the one set via 'public function getSlogan'

mrAceT avatar Jun 27 '24 13:06 mrAceT

Might have something to do with #25950 (and plus that the defaults.php never gets updated since we don't touch the themes/ folder during upgrades...)

Those this is still not what I'd expect:

https://github.com/nextcloud/server/blob/2d5060d1e3161aadfafb11d3690bc337b9092d31/core/src/components/login/LoginForm.vue#L169

joshtrichards avatar Oct 29 '24 18:10 joshtrichards

This issue persists in 31.0.2 - only some values from defaults.php are used.

The assignment to OC.theme.name is done here:

server/lib/private/Template/JSConfigHelper.php

Line 242 in 00aa8f5

'name' => $this->defaults->getName(),

Thanks for the info! If I cahange the values right there instead of using the getters (e.g. 'name' => "Test") they are changed everywhere in the UI immediately. Modifying https://github.com/nextcloud/server/blob/b03ffab5f0f39139c71cb2b8c370ca3f3d1ad391/lib/public/Defaults.php#L97 to return some test value has the same effect, however there seems to be an issue here getting the specified theming defaults: https://github.com/nextcloud/server/blob/b03ffab5f0f39139c71cb2b8c370ca3f3d1ad391/lib/public/Defaults.php#L32

1358 avatar Apr 01 '25 12:04 1358

So, deeper into the rabbit hole. The values from themes/.../defaults.php are overwritten as soon as there is a "name" specified in the database: https://github.com/nextcloud/server/blob/b03ffab5f0f39139c71cb2b8c370ca3f3d1ad391/apps/theming/lib/ThemingDefaults.php#L71

Returning $this->name (or replacing it with some smarter if statement) restores the theming behaviour including changing the login title as values in parent:: are all as expected.

Edit: Quick&Dirty workaround is e.g.:

  if ($this->name === "Nextcloud"):
    return strip_tags($this->config->getAppValue('theming', 'name', $this->name));
  else:
    return $this->name;
  endif;

and has to be adjusted for getHTMLName(), getTitle(), ... and all the other ones, too.

1358 avatar Apr 01 '25 13:04 1358

So, deeper into the rabbit hole...

Thanks for diving into it..

It's annoying but it isn't important enough for me to start "Q&D fixing it".. I already have a few of those.. and I need to redo them every time there is an update..

mrAceT avatar Apr 01 '25 14:04 mrAceT

Just to mention it here: This is very unlikely to be fixed. The theming using themes/ folder is deprecated since Nextcloud 22 and will be very likely removed in an upcoming version. Instead you can configure the instance name etc using the theming app in the administrator settings or using the occ command.

susnux avatar Apr 01 '25 22:04 susnux

.. The theming using themes/ folder is deprecated since Nextcloud 22 and will be very likely removed in an upcoming version..

Completely? If some styling / (re)branding would be possible, I would appreciate that verry much. I now access one NextCloud instance via two domains and the apperance is different on both of them.

If some basic styling & branding would be possible via the config.php, that would be fine too! Jusat let me give it an other name there and allow the option to add a CSS and all would be well?

mrAceT avatar Apr 02 '25 12:04 mrAceT

For now it seems to be quite easy to fix this without any side effects to other defaults by re-using existing logic: https://github.com/nextcloud/server/compare/master...1358:server:fix-legacy-theming

This goes hand in hand with the admin settings saying "You are already using a custom theme. Theming app settings might be overwritten by that." (not otherway round)

Still need to get the /apps/theming/image/logo-route to return the themed logo instead of the uploaded one...

1358 avatar Apr 02 '25 12:04 1358

Is there a chance to get a PR merged adressing all these legacy inconsistencies until the theming app is capable handling all of them (as there are several issues about this open right now)?

1358 avatar Jun 03 '25 18:06 1358

I guess https://github.com/1358/server/pull/1 would be an easy snatch to handle all that old issues until migration to the theming app is done.

1358 avatar Jun 15 '25 14:06 1358