Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/en/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

9 changes: 7 additions & 2 deletions modules/account/controllers/profile.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Jelix\Authentication\Account\Manager;
use Jelix\Authentication\Account\Account;
use Jelix\Authentication\Account\ProfileViewPageEvent;

class profileCtrl extends jController {

Expand All @@ -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;
}
Expand Down
43 changes: 43 additions & 0 deletions modules/account/lib/ProfileViewPageEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Jelix\Authentication\Account;

use jEvent;
use jTpl;

class ProfileViewPageEvent extends jEvent
{
private jTpl $tpl;

private $contentList = [];

public function __construct(jTpl $tpl)
{
$this->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;
}

}
4 changes: 4 additions & 0 deletions test/testapp/modules/test/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<event name="adminui.loading" />
<event name="adminui.dashboard.loading" />
</listener>

<listener name="\TestAuth\ProfileEventListener">
<event name="ProfileViewPageEvent" />
</listener>
</events>
21 changes: 21 additions & 0 deletions test/testapp/modules/test/lib/ProfileEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace TestAuth;

use Jelix\Authentication\Account\ProfileViewPageEvent;
use jEventListener;

class ProfileEventListener extends jEventListener
{
public function onProfileViewPageEvent(ProfileViewPageEvent $event)
{
$tpl = $event->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('<br>content on same position use insertion order (1)', 8);
$event->addContent('<br>content on same position use insertion order (2)', 8);
}
}
2 changes: 2 additions & 0 deletions test/testapp/modules/test/templates/profilePageExtended.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<br>content will be displayed {$position} the form
<br>