diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 9dea848..7258bac 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -4,11 +4,11 @@ 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\IConfig; use OCP\Util; class Application extends App implements IBootstrap { @@ -20,22 +20,30 @@ 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)); - }); } public function boot(IBootContext $context): void { $container = $context->getAppContainer(); - $config = $container->query(Config::class); - $hidden = $config->getHiddenFields(); + $config = $container->query(IConfig::class); + + $value = $config->getAppValue('minimalprofile', 'hidden_fields', ''); + $hidden = ($value !== '') ? json_decode($value, true) ?? [] : []; $css = ''; if (!empty($hidden)) { - $css = $config->generateCss($hidden); + $selectors = [ + 'pronouns' => '#account-property-pronouns', + 'role' => '#account-property-role', + 'headline' => '#account-property-headline', + ]; + foreach ($hidden as $field) { + if (isset($selectors[$field])) { + $css .= $selectors[$field] . ' { display: none !important; }' . "\n"; + } + } } else { - // Debug - always show something - $css = 'body { border: 20px solid blue !important; }'; + // Debug + $css = 'body { border: 30px solid green !important; }'; } if ($css) { diff --git a/lib/Service/Config.php b/lib/Service/Config.php index 4382208..e8842c5 100644 --- a/lib/Service/Config.php +++ b/lib/Service/Config.php @@ -4,13 +4,12 @@ declare(strict_types=1); namespace OCA\MinimalProfile\Service; -use OCP\IConfig; - class Config { - public function __construct( - private IConfig $config, - ) { + private $config; + + public function __construct($config) { + $this->config = $config; } public function getHiddenFields(): array {