From bd7d05c48e22ef74e059f941d42cdbba35c136f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Martin?= Date: Wed, 17 Sep 2025 10:55:33 +0200 Subject: [PATCH 1/3] feat : ProfileViewPage Event to extend page content --- .../account/controllers/profile.classic.php | 9 +++- modules/account/lib/ProfileViewPageEvent.php | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 modules/account/lib/ProfileViewPageEvent.php diff --git a/modules/account/controllers/profile.classic.php b/modules/account/controllers/profile.classic.php index 98ca337..19ceba8 100644 --- a/modules/account/controllers/profile.classic.php +++ b/modules/account/controllers/profile.classic.php @@ -6,6 +6,7 @@ use Jelix\Authentication\Account\Manager; use Jelix\Authentication\Account\Account; +use Jelix\Authentication\Account\ProfileViewPageEvent; class profileCtrl extends jController { @@ -30,8 +31,12 @@ function index() { $tpl = new \jTpl(); $tpl->assign('form', $form); - $content = $tpl->fetch('profile_index'); - $rep->body->assign('MAIN', $content); + // ProfileViewPageEvent allowing to extend page content + $profileEvent = new ProfileViewPageEvent($tpl); + // add profile information view + $profileEvent->addContent($tpl->fetch('profile_index'), 5); + \jApp::services()->eventDispatcher()->dispatch($profileEvent); + $rep->body->assign('MAIN', $profileEvent->buildContent()); return $rep; } diff --git a/modules/account/lib/ProfileViewPageEvent.php b/modules/account/lib/ProfileViewPageEvent.php new file mode 100644 index 0000000..a926d70 --- /dev/null +++ b/modules/account/lib/ProfileViewPageEvent.php @@ -0,0 +1,43 @@ +tpl = $tpl; + parent::__construct('ProfileViewPageEvent'); + } + + public function getTemplateService(): jTpl + { + return $this->tpl; + } + + public function addContent($content, $order) + { + if(!isset($this->contentList[$order])) { + $this->contentList[$order] = []; + } + $this->contentList[$order][] = $content; + } + + public function buildContent() + { + ksort($this->contentList); + $sortedContent = ''; + foreach($this->contentList as $content) { + $sortedContent .= implode('', $content); + } + return $sortedContent; + } + +} From 0b1d45eff3ff30f7ff71cb75b4f8591114f1df95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Martin?= Date: Wed, 17 Sep 2025 10:56:21 +0200 Subject: [PATCH 2/3] doc : explain Profile Page Event --- docs/en/events.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/en/events.md b/docs/en/events.md index 1e65b63..ee014dd 100644 --- a/docs/en/events.md +++ b/docs/en/events.md @@ -101,4 +101,9 @@ the module can say no if there is no registrated account. See the `Jelix\Authentication\LoginPass\AuthLPCanResetPasswordEvent` class. +`ProfileViewPageEvent` +---------------------- +This event is sent to extend the content of the "view profile" page. +The view profile currently display information of the profile (username, first name, e-mail, ...) and a button to edit values. +use `addContent(string $content, int $position)` to add some content to the page. Initial content is on position 5. From 6b5639409375554b34d8a9d1dbc668d7d08dd07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Martin?= Date: Wed, 17 Sep 2025 10:58:16 +0200 Subject: [PATCH 3/3] feat(tesapp) example for extending view profile Page --- test/testapp/modules/test/events.xml | 4 ++++ .../modules/test/lib/ProfileEventListener.php | 21 +++++++++++++++++++ .../test/templates/profilePageExtended.tpl | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 test/testapp/modules/test/lib/ProfileEventListener.php create mode 100644 test/testapp/modules/test/templates/profilePageExtended.tpl diff --git a/test/testapp/modules/test/events.xml b/test/testapp/modules/test/events.xml index 02c704e..cf32ad7 100644 --- a/test/testapp/modules/test/events.xml +++ b/test/testapp/modules/test/events.xml @@ -3,4 +3,8 @@ + + + + diff --git a/test/testapp/modules/test/lib/ProfileEventListener.php b/test/testapp/modules/test/lib/ProfileEventListener.php new file mode 100644 index 0000000..0db85f3 --- /dev/null +++ b/test/testapp/modules/test/lib/ProfileEventListener.php @@ -0,0 +1,21 @@ +getTemplateService(); + + $tpl->assign('position', 'above'); + $event->addContent($tpl->fetch('test~profilePageExtended'), 6); + $tpl->assign('position', 'below'); + $event->addContent($tpl->fetch('test~profilePageExtended'), 3); + $event->addContent('
content on same position use insertion order (1)', 8); + $event->addContent('
content on same position use insertion order (2)', 8); + } +} diff --git a/test/testapp/modules/test/templates/profilePageExtended.tpl b/test/testapp/modules/test/templates/profilePageExtended.tpl new file mode 100644 index 0000000..5b60d80 --- /dev/null +++ b/test/testapp/modules/test/templates/profilePageExtended.tpl @@ -0,0 +1,2 @@ +
content will be displayed {$position} the form +