diff --git a/modules/mod_login/mod_login.php b/modules/mod_login/mod_login.php
deleted file mode 100644
index 98c89faea69f7..0000000000000
--- a/modules/mod_login/mod_login.php
+++ /dev/null
@@ -1,34 +0,0 @@
-
- * @license GNU General Public License version 2 or later; see LICENSE.txt
- */
-
-\defined('_JEXEC') or die;
-
-use Joomla\CMS\Factory;
-use Joomla\CMS\Helper\AuthenticationHelper;
-use Joomla\CMS\Helper\ModuleHelper;
-use Joomla\Module\Login\Site\Helper\LoginHelper;
-
-$params->def('greeting', 1);
-
-// HTML IDs
-$formId = 'login-form-' . $module->id;
-$type = LoginHelper::getType();
-$return = LoginHelper::getReturnUrl($params, $type);
-$registerLink = LoginHelper::getRegistrationUrl($params);
-$extraButtons = AuthenticationHelper::getLoginButtons($formId);
-$user = Factory::getUser();
-$layout = $params->get('layout', 'default');
-
-// Logged users must load the logout sublayout
-if (!$user->guest) {
- $layout .= '_logout';
-}
-
-require ModuleHelper::getLayoutPath('mod_login', $layout);
diff --git a/modules/mod_login/mod_login.xml b/modules/mod_login/mod_login.xml
index 1edb11c914c8a..9c6278c8a177b 100644
--- a/modules/mod_login/mod_login.xml
+++ b/modules/mod_login/mod_login.xml
@@ -11,7 +11,7 @@
MOD_LOGIN_XML_DESCRIPTION
Joomla\Module\Login
- mod_login.php
+ services
src
tmpl
diff --git a/modules/mod_login/services/provider.php b/modules/mod_login/services/provider.php
new file mode 100644
index 0000000000000..0b99ae7fe6caa
--- /dev/null
+++ b/modules/mod_login/services/provider.php
@@ -0,0 +1,41 @@
+
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+\defined('_JEXEC') or die;
+
+use Joomla\CMS\Extension\Service\Provider\HelperFactory;
+use Joomla\CMS\Extension\Service\Provider\Module;
+use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
+use Joomla\DI\Container;
+use Joomla\DI\ServiceProviderInterface;
+
+/**
+ * The login module service provider.
+ *
+ * @since __DEPLOY_VERSION__
+ */
+return new class () implements ServiceProviderInterface {
+ /**
+ * Registers the service provider with a DI container.
+ *
+ * @param Container $container The DI container.
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function register(Container $container)
+ {
+ $container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Login'));
+ $container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Login\\Site\\Helper'));
+
+ $container->registerServiceProvider(new Module());
+ }
+};
diff --git a/modules/mod_login/src/Dispatcher/Dispatcher.php b/modules/mod_login/src/Dispatcher/Dispatcher.php
new file mode 100644
index 0000000000000..6d6d6c2c82085
--- /dev/null
+++ b/modules/mod_login/src/Dispatcher/Dispatcher.php
@@ -0,0 +1,103 @@
+
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+namespace Joomla\Module\Login\Site\Dispatcher;
+
+use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
+use Joomla\CMS\Helper\AuthenticationHelper;
+use Joomla\CMS\Helper\HelperFactoryAwareInterface;
+use Joomla\CMS\Helper\HelperFactoryAwareTrait;
+use Joomla\CMS\Helper\ModuleHelper;
+
+// phpcs:disable PSR1.Files.SideEffects
+\defined('_JEXEC') or die;
+// phpcs:enable PSR1.Files.SideEffects
+
+/**
+ * Dispatcher class for mod_login
+ *
+ * @since __DEPLOY_VERSION__
+ */
+class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
+{
+ use HelperFactoryAwareTrait;
+
+ /**
+ * Runs the dispatcher.
+ *
+ * @return void
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function dispatch()
+ {
+ $this->loadLanguage();
+
+ $displayData = $this->getLayoutData();
+
+ // Stop when display data is false
+ if ($displayData === false) {
+ return;
+ }
+
+ // Execute the layout without the module context
+ $loader = static function (array $displayData) {
+ // If $displayData doesn't exist in extracted data, unset the variable.
+ if (!\array_key_exists('displayData', $displayData)) {
+ extract($displayData);
+ unset($displayData);
+ } else {
+ extract($displayData);
+ }
+
+ /**
+ * Extracted variables
+ * -----------------
+ * @var \stdClass $module
+ * @var Registry $params
+ */
+
+ // Logged users must load the logout sublayout
+ if (!$user->guest) {
+ $layout .= '_logout';
+ }
+
+ require ModuleHelper::getLayoutPath('mod_login', $layout);
+ };
+
+ $loader($displayData);
+ }
+
+ /**
+ * Returns the layout data.
+ *
+ * @return array
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ protected function getLayoutData()
+ {
+ $data = parent::getLayoutData();
+ $helper = $this->getHelperFactory()->getHelper('LoginHelper');
+
+ $data['params']->def('greeting', 1);
+
+ // HTML IDs
+ $formId = 'login-form-' . $data['module']->id;
+ $data['user'] = $data['app']->getIdentity();
+ $type = $helper->getUserType($data['user']);
+ $data['return'] = $helper->getReturnUrlString($data['params'], $type, $data['app']);
+ $data['registerLink'] = $helper->getRegistrationUrlString($data['params'], $data['app']);
+ $data['extraButtons'] = AuthenticationHelper::getLoginButtons($formId);
+ $data['layout'] = $data['params']->get('layout', 'default');
+
+ return $data;
+ }
+}
diff --git a/modules/mod_login/src/Helper/LoginHelper.php b/modules/mod_login/src/Helper/LoginHelper.php
index 990729c9cb8f1..a942d8a2efa8a 100644
--- a/modules/mod_login/src/Helper/LoginHelper.php
+++ b/modules/mod_login/src/Helper/LoginHelper.php
@@ -10,9 +10,12 @@
namespace Joomla\Module\Login\Site\Helper;
+use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Uri\Uri;
+use Joomla\CMS\User\User;
+use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
@@ -28,14 +31,17 @@ class LoginHelper
/**
* Retrieve the URL where the user should be returned after logging in
*
- * @param \Joomla\Registry\Registry $params module parameters
- * @param string $type return type
+ * @param Registry $params module parameters
+ * @param string $type return type
+ * @param CMSApplicationInterface $app The application
+ *
+ * @since __DEPLOY_VERSION__
*
* @return string
*/
- public static function getReturnUrl($params, $type)
+ public function getReturnUrlString(Registry $params, $type, CMSApplicationInterface $app): string
{
- $item = Factory::getApplication()->getMenu()->getItem($params->get($type));
+ $item = $app->getMenu()->getItem($params->get($type));
// Stay on the same page
$url = Uri::getInstance()->toString();
@@ -56,30 +62,34 @@ public static function getReturnUrl($params, $type)
/**
* Returns the current users type
*
+ * @param User $user The user object
+ *
* @return string
+ *
+ * @since __DEPLOY_VERSION__
*/
- public static function getType()
+ public function getUserType(User $user): string
{
- $user = Factory::getUser();
-
return (!$user->guest) ? 'logout' : 'login';
}
/**
* Retrieve the URL for the registration page
*
- * @param \Joomla\Registry\Registry $params module parameters
+ * @param Registry $params module parameters
+ *
+ * @since __DEPLOY_VERSION__
*
* @return string
*/
- public static function getRegistrationUrl($params)
+ public function getRegistrationUrlString(Registry $params, CMSApplicationInterface $app): string
{
$regLink = 'index.php?option=com_users&view=registration';
$regLinkMenuId = $params->get('customRegLinkMenu');
// If there is a custom menu item set for registration => override default
if ($regLinkMenuId) {
- $item = Factory::getApplication()->getMenu()->getItem($regLinkMenuId);
+ $item = $app->getMenu()->getItem($regLinkMenuId);
if ($item) {
$regLink = 'index.php?Itemid=' . $regLinkMenuId;
@@ -92,4 +102,59 @@ public static function getRegistrationUrl($params)
return $regLink;
}
+
+ /**
+ * Retrieve the URL where the user should be returned after logging in
+ *
+ * @param Registry $params module parameters
+ * @param string $type return type
+ *
+ * @return string
+ *
+ * @deprecated __DEPLOY_VERSION__ will be removed in 7.0
+ * Use the non-static method getReturnUrlString
+ * Example: Factory::getApplication()->bootModule('mod_login', 'site')
+ * ->getHelper('LoginHelper')
+ * ->getReturnUrlString($params, $type, Factory::getApplication())
+ */
+ public static function getReturnUrl($params, $type)
+ {
+ return (new self())->getReturnUrlString($params, $type, Factory::getApplication());
+ }
+
+ /**
+ * Returns the current users type
+ *
+ * @return string
+ *
+ * @deprecated __DEPLOY_VERSION__ will be removed in 7.0
+ * Use the non-static method getUserType
+ * Example: Factory::getApplication()->bootModule('mod_login', 'site')
+ * ->getHelper('LoginHelper')
+ * ->getUserType(Factory::getApplication())
+ */
+ public static function getType()
+ {
+ $user = Factory::getApplication()->getIdentity();
+
+ return (new self())->getUserType($user);
+ }
+
+ /**
+ * Retrieve the URL for the registration page
+ *
+ * @param Registry $params module parameters
+ *
+ * @return string
+ *
+ * @deprecated __DEPLOY_VERSION__ will be removed in 7.0
+ * Use the non-static method getRegistrationUrlString
+ * Example: Factory::getApplication()->bootModule('mod_login', 'site')
+ * ->getHelper('LoginHelper')
+ * ->getRegistrationUrlString($params, Factory::getApplication())
+ */
+ public static function getRegistrationUrl($params)
+ {
+ return (new self())->getRegistrationUrlString($params, Factory::getApplication());
+ }
}