From a992559e09bf8a366254f83f26cdb5184754cb3f Mon Sep 17 00:00:00 2001 From: Guy Van Sanden Date: Thu, 16 Apr 2026 15:00:27 +0200 Subject: [PATCH] Read config and generate dynamic CSS --- lib/AppInfo/Application.php | 52 ++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index b80e7d9..ce0f562 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -9,6 +9,7 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; use OCP\Util; class Application extends App implements IBootstrap { @@ -20,14 +21,59 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { + $context->registerService(IConfig::class, function($c) { + return $c->get(IConfig::class); + }); + $context->registerEventListener( TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, - function() { - Util::addStyle('minimalprofile', 'minimalprofile'); - } + LoadStylesListener::class ); } public function boot(IBootContext $context): void { } +} + +class LoadStylesListener { + private IConfig $config; + + public function __construct(IConfig $config) { + $this->config = $config; + } + + public function __invoke(): void { + $value = $this->config->getAppValue('minimalprofile', 'hidden_fields', ''); + $hidden = ($value !== '') ? json_decode($value, true) ?? [] : []; + + if (empty($hidden)) { + return; + } + + $selectors = [ + 'pronouns' => '#account-property-pronouns', + 'role' => '#account-property-role', + 'headline' => '#account-property-headline', + 'biography' => '#account-property-biography', + 'organisation' => '#account-property-organisation', + 'phone' => '#account-property-phone', + 'address' => '#account-property-address', + 'birthdate' => '#account-property-birthdate', + 'website' => '#account-property-website', + 'twitter' => '#account-property-twitter', + 'fediverse' => '#account-property-fediverse', + 'location' => '#account-property-location', + ]; + + $css = ''; + foreach ($hidden as $field) { + if (isset($selectors[$field])) { + $css .= '.personal-settings-setting-box:has(' . $selectors[$field] . ') { display: none !important; }' . "\n"; + } + } + + if ($css) { + Util::addInlineStyle($css); + } + } } \ No newline at end of file