mirror of
https://github.com/friendica/friendica
synced 2025-03-04 05:48:26 +00:00
Implement home_init hook as Event
This commit is contained in:
parent
aabf9a8b01
commit
742cde89e6
5 changed files with 19 additions and 8 deletions
|
@ -35,6 +35,7 @@ final class HookEventBridge
|
|||
*/
|
||||
private static array $eventMapper = [
|
||||
Event::INIT => 'init_1',
|
||||
Event::HOME_INIT => 'home_init',
|
||||
ConfigLoadedEvent::CONFIG_LOADED => 'load_config',
|
||||
ArrayFilterEvent::APP_MENU => 'app_menu',
|
||||
ArrayFilterEvent::NAV_INFO => 'nav_info',
|
||||
|
@ -57,6 +58,7 @@ final class HookEventBridge
|
|||
{
|
||||
return [
|
||||
Event::INIT => 'onNamedEvent',
|
||||
Event::HOME_INIT => 'onNamedEvent',
|
||||
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
||||
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
||||
|
|
|
@ -21,6 +21,8 @@ class Event implements NamedEvent
|
|||
*/
|
||||
public const INIT = 'friendica.init';
|
||||
|
||||
public const HOME_INIT = 'friendica.home_init';
|
||||
|
||||
private string $name;
|
||||
|
||||
public function __construct(string $name)
|
||||
|
|
|
@ -11,6 +11,7 @@ use Friendica\BaseModule;
|
|||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\DI;
|
||||
use Friendica\Event\Event;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Security\Login;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
|
@ -34,11 +35,11 @@ class Home extends BaseModule
|
|||
{
|
||||
$basePath = DI::appHelper()->getBasePath();
|
||||
$config = DI::config();
|
||||
$eventDispatcher = DI::eventDispatcher();
|
||||
|
||||
// currently no returned data is used
|
||||
$ret = [];
|
||||
|
||||
Hook::callAll('home_init', $ret);
|
||||
$eventDispatcher->dispatch(
|
||||
new Event(Event::HOME_INIT)
|
||||
);
|
||||
|
||||
if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserNickname())) {
|
||||
DI::baseUrl()->redirect('network');
|
||||
|
|
|
@ -12,11 +12,11 @@ use Friendica\App\BaseURL;
|
|||
use Friendica\AppHelper;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Contact\Introduction\Repository\Introduction;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Event\Event;
|
||||
use Friendica\Model\Notification;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Response;
|
||||
|
@ -25,6 +25,7 @@ use Friendica\Navigation\SystemMessages;
|
|||
use Friendica\Network\HTTPException\ForbiddenException;
|
||||
use Friendica\Security\Authentication;
|
||||
use Friendica\Util;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
@ -46,8 +47,9 @@ class Delegation extends BaseModule
|
|||
private $intro;
|
||||
/** @var AppHelper */
|
||||
private $appHelper;
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
public function __construct(AppHelper $appHelper, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
public function __construct(EventDispatcherInterface $eventDispatcher, AppHelper $appHelper, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
|
@ -58,6 +60,7 @@ class Delegation extends BaseModule
|
|||
$this->notify = $notify;
|
||||
$this->intro = $intro;
|
||||
$this->appHelper = $appHelper;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
|
@ -128,8 +131,9 @@ class Delegation extends BaseModule
|
|||
$this->session->setSubManagedUserId($original_id);
|
||||
}
|
||||
|
||||
$ret = [];
|
||||
Hook::callAll('home_init', $ret);
|
||||
$this->eventDispatcher->dispatch(
|
||||
new Event(Event::HOME_INIT)
|
||||
);
|
||||
|
||||
$this->systemMessages->addNotice($this->t('You are now logged in as %s', $user['username']));
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ class HookEventBridgeTest extends TestCase
|
|||
{
|
||||
$expected = [
|
||||
Event::INIT => 'onNamedEvent',
|
||||
Event::HOME_INIT => 'onNamedEvent',
|
||||
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
||||
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
||||
|
@ -61,6 +62,7 @@ class HookEventBridgeTest extends TestCase
|
|||
return [
|
||||
['test', 'test'],
|
||||
[Event::INIT, 'init_1'],
|
||||
[Event::HOME_INIT, 'home_init'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue