Use Util::addInlineStyle in event listener

This commit is contained in:
2026-04-16 14:37:17 +02:00
parent 93fa190e5e
commit 4190154853
2 changed files with 66 additions and 3 deletions

View File

@@ -4,13 +4,14 @@ declare(strict_types=1);
namespace OCA\MinimalProfile\AppInfo;
use OCA\MinimalProfile\Service\Config;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;
class Application extends App implements IBootstrap {
@@ -21,11 +22,23 @@ class Application extends App implements IBootstrap {
}
public function register(IRegistrationContext $context): void {
$context->registerService(Config::class, function($c) {
return new Config($c->get(\OCP\IConfig::class));
});
$context->registerEventListener(
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
function(Event $event) {
if ($event instanceof TemplateResponse) {
$event->getStyleSheet()->load('minimalprofile', 'minimalprofile');
if (!($event instanceof TemplateResponse)) {
return;
}
$container = $event->getAppContainer();
$config = $container->query(Config::class);
$hidden = $config->getHiddenFields();
if (!empty($hidden)) {
$css = $config->generateCss($hidden);
Util::addInlineStyle($css);
}
}
);