Files
nextcloud_minimalprofile/lib/AppInfo/Application.php

79 lines
1.9 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace OCA\MinimalProfile\AppInfo;
2026-04-16 14:50:02 +02:00
use OCA\MinimalProfile\Service\Config;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
2026-04-16 14:50:02 +02:00
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
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 {
2026-04-16 14:50:02 +02:00
$context->registerService(Config::class, function($c) {
return new Config($c->get(IConfig::class));
});
$context->registerEventListener(
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
TemplateListener::class
);
}
public function boot(IBootContext $context): void {
2026-04-16 14:50:02 +02:00
}
}
class TemplateListener implements IEventListener {
private Config $config;
public function __construct(Config $config) {
$this->config = $config;
}
public function handle(Event $event): void {
if (!($event instanceof TemplateResponse)) {
return;
}
$hidden = $this->config->getHiddenFields();
2026-04-16 14:39:12 +02:00
2026-04-16 14:50:02 +02:00
$debugCss = '#content { border: 30px solid cyan !important; }';
2026-04-16 14:48:54 +02:00
Util::addInlineStyle($debugCss);
2026-04-16 14:47:59 +02:00
$css = '';
2026-04-16 14:39:12 +02:00
if (!empty($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";
}
}
2026-04-16 14:39:12 +02:00
}
2026-04-16 14:42:29 +02:00
2026-04-16 14:47:59 +02:00
if ($css) {
Util::addInlineStyle($css);
}
2026-04-16 14:50:02 +02:00
file_put_contents('/tmp/minimalprofile_debug.log', date('Y-m-d H:i:s') . ' TemplateListener ran, hidden: ' . print_r($hidden, true) . "\n", FILE_APPEND);
}
}