Read config and generate dynamic CSS
This commit is contained in:
@@ -9,6 +9,7 @@ use OCP\AppFramework\Bootstrap\IBootContext;
|
|||||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\IConfig;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
|
||||||
class Application extends App implements IBootstrap {
|
class Application extends App implements IBootstrap {
|
||||||
@@ -20,14 +21,59 @@ class Application extends App implements IBootstrap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function register(IRegistrationContext $context): void {
|
public function register(IRegistrationContext $context): void {
|
||||||
|
$context->registerService(IConfig::class, function($c) {
|
||||||
|
return $c->get(IConfig::class);
|
||||||
|
});
|
||||||
|
|
||||||
$context->registerEventListener(
|
$context->registerEventListener(
|
||||||
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
|
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
|
||||||
function() {
|
LoadStylesListener::class
|
||||||
Util::addStyle('minimalprofile', 'minimalprofile');
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(IBootContext $context): void {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user