Use template event listener approach
This commit is contained in:
@@ -4,10 +4,14 @@ 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\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\EventDispatcher\Event;
|
||||||
|
use OCP\EventDispatcher\IEventListener;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
|
||||||
@@ -20,17 +24,36 @@ 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(IConfig::class));
|
||||||
|
});
|
||||||
|
|
||||||
|
$context->registerEventListener(
|
||||||
|
TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS,
|
||||||
|
TemplateListener::class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(IBootContext $context): void {
|
public function boot(IBootContext $context): void {
|
||||||
$container = $context->getAppContainer();
|
}
|
||||||
$config = $container->query(IConfig::class);
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
$value = $config->getAppValue('minimalprofile', 'hidden_fields', '');
|
$debugCss = '#content { border: 30px solid cyan !important; }';
|
||||||
$hidden = ($value !== '') ? json_decode($value, true) ?? [] : [];
|
|
||||||
|
|
||||||
// Debug first - always add this to prove CSS is being added
|
|
||||||
$debugCss = '#content { border: 50px solid purple !important; }';
|
|
||||||
Util::addInlineStyle($debugCss);
|
Util::addInlineStyle($debugCss);
|
||||||
|
|
||||||
$css = '';
|
$css = '';
|
||||||
@@ -51,6 +74,6 @@ class Application extends App implements IBootstrap {
|
|||||||
Util::addInlineStyle($css);
|
Util::addInlineStyle($css);
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents('/tmp/minimalprofile_debug.log', date('Y-m-d H:i:s') . ' Hidden: ' . print_r($hidden, true) . ' CSS: ' . $css . "\n", FILE_APPEND);
|
file_put_contents('/tmp/minimalprofile_debug.log', date('Y-m-d H:i:s') . ' TemplateListener ran, hidden: ' . print_r($hidden, true) . "\n", FILE_APPEND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user