Files
nextcloud_minimalprofile/lib/AppInfo/Application.php

79 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\MinimalProfile\AppInfo;
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\IConfig;
use OCP\Util;
class Application extends App implements IBootstrap {
public const APP_ID = 'minimalprofile';
public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
}
public function register(IRegistrationContext $context): void {
$context->registerService(IConfig::class, function($c) {
return $c->get(IConfig::class);
});
$context->registerEventListener(
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
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);
}
}
}