From 4190154853ee0c09bd89b12f6d5786f01ba9d2c8 Mon Sep 17 00:00:00 2001 From: Guy Van Sanden Date: Thu, 16 Apr 2026 14:37:17 +0200 Subject: [PATCH] Use Util::addInlineStyle in event listener --- lib/AppInfo/Application.php | 19 +++++++++++--- lib/Service/Config.php | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 lib/Service/Config.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index e814eff..dc9f028 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -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); } } ); diff --git a/lib/Service/Config.php b/lib/Service/Config.php new file mode 100644 index 0000000..4382208 --- /dev/null +++ b/lib/Service/Config.php @@ -0,0 +1,50 @@ +config->getAppValue('minimalprofile', 'hidden_fields', ''); + if ($value === '') { + return []; + } + return json_decode($value, true) ?? []; + } + + public function generateCss(array $fields): string { + $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 ($fields as $field) { + if (isset($selectors[$field])) { + $selector = $selectors[$field]; + $css .= $selector . ' { display: none !important; }' . "\n"; + $css .= '.personal-settings-setting-box:has(' . $selector . ') { display: none !important; }' . "\n"; + } + } + return $css; + } +} \ No newline at end of file