v1.0.21 - boot() reads config, adds inline CSS, logs to /tmp/mp_loaded.log
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<name>Minimal Profile</name>
|
<name>Minimal Profile</name>
|
||||||
<summary>Hides profile fields to create a minimal user profile</summary>
|
<summary>Hides profile fields to create a minimal user profile</summary>
|
||||||
<description>Allows administrators to hide profile fields like pronouns, social links, etc.</description>
|
<description>Allows administrators to hide profile fields like pronouns, social links, etc.</description>
|
||||||
<version>1.0.20</version>
|
<version>1.0.21</version>
|
||||||
<licence>AGPL</licence>
|
<licence>AGPL</licence>
|
||||||
<author>Your Name</author>
|
<author>Your Name</author>
|
||||||
<namespace>MinimalProfile</namespace>
|
<namespace>MinimalProfile</namespace>
|
||||||
|
|||||||
@@ -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,17 +21,41 @@ class Application extends App implements IBootstrap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function register(IRegistrationContext $context): void {
|
public function register(IRegistrationContext $context): void {
|
||||||
// Register event listener - this fires on EVERY page render after template is built
|
$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() {
|
function() {
|
||||||
Util::addStyle('minimalprofile', 'minimalprofile');
|
Util::addStyle('minimalprofile', 'minimalprofile');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
file_put_contents('/tmp/minimalprofile.log', date('Y-m-d H:i:s') . ' register, event registered' . "\n", FILE_APPEND);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(IBootContext $context): void {
|
public function boot(IBootContext $context): void {
|
||||||
|
$config = $context->getAppContainer()->query(IConfig::class);
|
||||||
|
$value = $config->getAppValue('minimalprofile', 'hidden_fields', '');
|
||||||
|
$hidden = ($value !== '') ? json_decode($value, true) ?? [] : [];
|
||||||
|
|
||||||
|
$css = '';
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($css) {
|
||||||
|
Util::addInlineStyle($css);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents('/tmp/mp_loaded.log', date('Y-m-d H:i:s') . ' boot ran, hidden: ' . print_r($hidden, true) . ", css: $css\n", FILE_APPEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user