Simplify: direct IConfig query, green border
This commit is contained in:
@@ -4,11 +4,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace OCA\MinimalProfile\AppInfo;
|
namespace OCA\MinimalProfile\AppInfo;
|
||||||
|
|
||||||
use OCA\MinimalProfile\Service\Config;
|
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
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\IConfig;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
|
||||||
class Application extends App implements IBootstrap {
|
class Application extends App implements IBootstrap {
|
||||||
@@ -20,22 +20,30 @@ class Application extends App implements IBootstrap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function register(IRegistrationContext $context): void {
|
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 {
|
public function boot(IBootContext $context): void {
|
||||||
$container = $context->getAppContainer();
|
$container = $context->getAppContainer();
|
||||||
$config = $container->query(Config::class);
|
$config = $container->query(IConfig::class);
|
||||||
$hidden = $config->getHiddenFields();
|
|
||||||
|
$value = $config->getAppValue('minimalprofile', 'hidden_fields', '');
|
||||||
|
$hidden = ($value !== '') ? json_decode($value, true) ?? [] : [];
|
||||||
|
|
||||||
$css = '';
|
$css = '';
|
||||||
if (!empty($hidden)) {
|
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 {
|
} else {
|
||||||
// Debug - always show something
|
// Debug
|
||||||
$css = 'body { border: 20px solid blue !important; }';
|
$css = 'body { border: 30px solid green !important; }';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($css) {
|
if ($css) {
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace OCA\MinimalProfile\Service;
|
namespace OCA\MinimalProfile\Service;
|
||||||
|
|
||||||
use OCP\IConfig;
|
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
|
|
||||||
public function __construct(
|
private $config;
|
||||||
private IConfig $config,
|
|
||||||
) {
|
public function __construct($config) {
|
||||||
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHiddenFields(): array {
|
public function getHiddenFields(): array {
|
||||||
|
|||||||
Reference in New Issue
Block a user