Fix: Use event listener to load scripts on all pages

This commit is contained in:
2026-04-16 14:19:15 +02:00
parent a445c08d8a
commit 2057cf8e98
2 changed files with 19 additions and 4 deletions

View File

@@ -4,7 +4,7 @@
<name>Minimal Profile</name> <name>Minimal Profile</name>
<summary>Hides profile fields to create a minimal user profile</summary> <summary>Hides profile fields to create a minimal user profile</summary>
<description>Allows administrators to hide profile fields like pronouns, social links, etc.</description> <description>Allows administrators to hide profile fields like pronouns, social links, etc.</description>
<version>1.0.4</version> <version>1.0.5</version>
<licence>AGPL</licence> <licence>AGPL</licence>
<author>Your Name</author> <author>Your Name</author>
<namespace>MinimalProfile</namespace> <namespace>MinimalProfile</namespace>
@@ -14,7 +14,4 @@
<dependencies> <dependencies>
<nextcloud min-version="33" max-version="33"/> <nextcloud min-version="33" max-version="33"/>
</dependencies> </dependencies>
<scripts>
<script>minimalprofile</script>
</scripts>
</info> </info>

View File

@@ -8,6 +8,9 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
class Application extends App implements IBootstrap { class Application extends App implements IBootstrap {
@@ -18,8 +21,23 @@ class Application extends App implements IBootstrap {
} }
public function register(IRegistrationContext $context): void { public function register(IRegistrationContext $context): void {
$context->registerEventListener(
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
LoadScriptsListener::class
);
} }
public function boot(IBootContext $context): void { public function boot(IBootContext $context): void {
} }
}
class LoadScriptsListener implements IEventListener {
public function handle(Event $event): void {
if (!$event instanceof TemplateResponse) {
return;
}
$event->addScript('minimalprofile');
}
} }