Skip to content

Commit 017da7f

Browse files
committed
Refactor modules to modern Joomla 4.x structure
- https://manual.joomla.org/docs/building-extensions/modules/
1 parent 92bf90c commit 017da7f

19 files changed

Lines changed: 297 additions & 111 deletions

File tree

src/administrator/modules/mod_externallogin_admin/mod_externallogin_admin.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/administrator/modules/mod_externallogin_admin/mod_externallogin_admin.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<extension type="module" version="3" client="administrator" method="upgrade">
2+
<extension type="module" version="4" client="administrator" method="upgrade">
33

44
<name>MOD_EXTERNALLOGIN_ADMIN</name>
55

66
<!-- The following elements are optional and free of formatting conttraints -->
7-
<creationDate>July 2008</creationDate>
7+
<creationDate>Oct 2025</creationDate>
88
<author>Christophe Demko, Ioannis Barounis, Alexandre Gandois, others, see contributor page</author>
99
<authorUrl>https://github.com/akunzai/joomla-external-login</authorUrl>
1010
<license>GNU General Public License version 2 or later; see LICENSE</license>
@@ -15,10 +15,14 @@
1515
<!-- The description is optional and defaults to the name -->
1616
<description>MOD_EXTERNALLOGIN_ADMIN_DESCRIPTION</description>
1717

18+
<namespace path="src">Joomla\Module\ExternalloginAdmin</namespace>
19+
1820
<files>
19-
<filename module="mod_externallogin_admin">mod_externallogin_admin.php</filename>
20-
<filename>helper.php</filename>
21+
<folder module="mod_externallogin_admin">services</folder>
22+
<folder>language</folder>
23+
<folder>src</folder>
2124
<folder>tmpl</folder>
25+
<file>mod_externallogin_admin.xml</file>
2226
</files>
2327

2428
<languages>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
defined('_JEXEC') or die;
4+
5+
use Joomla\CMS\Extension\Service\Provider\HelperFactory;
6+
use Joomla\CMS\Extension\Service\Provider\Module;
7+
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
8+
use Joomla\DI\Container;
9+
use Joomla\DI\ServiceProviderInterface;
10+
11+
return new class () implements ServiceProviderInterface {
12+
/**
13+
* @since 5.0.0
14+
*/
15+
public function register(Container $container)
16+
{
17+
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\ExternalloginAdmin'));
18+
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\ExternalloginAdmin\\Administrator\\Helper'));
19+
$container->registerServiceProvider(new Module());
20+
}
21+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* @author Christophe Demko <chdemko@gmail.com>
5+
* @author Ioannis Barounis <contact@johnbarounis.com>
6+
* @author Alexandre Gandois <alexandre.gandois@etudiant.univ-lr.fr>
7+
* @copyright Copyright (C) 2008-2018 Christophe Demko, Ioannis Barounis, Alexandre Gandois. All rights reserved.
8+
* @license GNU General Public License, version 2. http://www.gnu.org/licenses/gpl-2.0.html
9+
*
10+
* @link https://github.com/akunzai/joomla-external-login
11+
*/
12+
13+
namespace Joomla\Module\ExternalloginAdmin\Administrator\Dispatcher;
14+
15+
defined('_JEXEC') or die;
16+
17+
use Joomla\CMS\Component\ComponentHelper;
18+
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
19+
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
20+
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
21+
use Joomla\CMS\Plugin\PluginHelper;
22+
use Joomla\Module\ExternalloginAdmin\Administrator\Helper\ExternalloginAdminHelper;
23+
use Joomla\Registry\Registry;
24+
25+
/**
26+
* Module dispatcher for mod_externallogin_admin.
27+
*
28+
* @since 5.0.0
29+
*/
30+
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
31+
{
32+
use HelperFactoryAwareTrait;
33+
34+
/**
35+
* Retrieve the layout data.
36+
*
37+
* @return array<string, mixed>
38+
*/
39+
protected function getLayoutData(): array
40+
{
41+
$data = parent::getLayoutData();
42+
43+
/** @var Registry $params */
44+
$params = $data['params'];
45+
46+
$data['enabled'] = ComponentHelper::getComponent('com_externallogin', true)->enabled
47+
&& PluginHelper::isEnabled('authentication', 'externallogin');
48+
49+
/** @var ExternalloginAdminHelper $helper */
50+
$helper = $this->getHelperFactory()->getHelper('ExternalloginAdminHelper');
51+
$servers = $helper->getServers($params);
52+
53+
$data['servers'] = $servers;
54+
$data['count'] = count($servers);
55+
56+
return $data;
57+
}
58+
}

src/administrator/modules/mod_externallogin_admin/helper.php renamed to src/administrator/modules/mod_externallogin_admin/src/Helper/ExternalloginAdminHelper.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,43 @@
1010
* @link https://github.com/akunzai/joomla-external-login
1111
*/
1212

13+
namespace Joomla\Module\ExternalloginAdmin\Administrator\Helper;
14+
15+
defined('_JEXEC') or die;
16+
17+
use Joomla\CMS\Event\Content\ContentPrepareEvent;
1318
use Joomla\CMS\Factory;
14-
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
15-
use Joomla\CMS\Uri\Uri;
19+
use Joomla\CMS\MVC\Factory\MVCFactoryServiceInterface;
1620
use Joomla\CMS\Router\Route;
21+
use Joomla\CMS\Uri\Uri;
22+
use Joomla\Component\Externallogin\Administrator\Model\ServersModel;
23+
use Joomla\Event\DispatcherInterface;
1724
use Joomla\Registry\Registry;
1825

19-
// No direct access to this file
20-
defined('_JEXEC') or die;
21-
2226
/**
23-
* Module helper class.
27+
* Helper providing data for the administrator module.
2428
*
25-
* @since 2.0.0
29+
* @since 5.0.0
2630
*/
27-
abstract class ModExternalloginadminHelper
31+
class ExternalloginAdminHelper
2832
{
2933
/**
30-
* Get the URLs of servers.
34+
* Retrieve enabled external login servers for the module.
3135
*
3236
* @param Registry $params Module parameters
3337
*
34-
* @return array Array of URL
38+
* @return array<int, object>
3539
*/
36-
public static function getListServersURL($params)
40+
public function getServers(Registry $params): array
3741
{
3842
$app = Factory::getApplication();
3943
$uri = Uri::getInstance();
4044

41-
// Get an instance of the generic articles model
42-
/** @var ExternalloginModelServers */
43-
$mvcFactory = $app->bootComponent('com_externallogin')->getMVCFactory();
45+
/** @var MVCFactoryServiceInterface $component */
46+
$component = $app->bootComponent('com_externallogin');
47+
$mvcFactory = $component->getMVCFactory();
48+
49+
/** @var ServersModel $model */
4450
$model = $mvcFactory->createModel('Servers', 'Administrator', ['ignore_request' => true]);
4551
$model->setState('filter.published', 1);
4652
$model->setState('filter.enabled', 1);
@@ -49,20 +55,35 @@ public static function getListServersURL($params)
4955
$model->setState('list.limit', 0);
5056
$model->setState('list.ordering', 'a.ordering');
5157
$model->setState('list.direction', 'ASC');
58+
5259
$items = $model->getItems();
5360

5461
foreach ($items as $i => $item) {
5562
$item->params = new Registry($item->params);
63+
5664
$uri->setVar('server', $item->id);
57-
$results = $app->getDispatcher()->dispatch('onGetLoginUrl', new Joomla\Event\Event('onGetLoginUrl', [$item, Route::_($uri, true)]))->getArgument('result', []);
65+
66+
$dispatcher = Factory::getContainer()->get(DispatcherInterface::class);
67+
$event = new ContentPrepareEvent(
68+
'onGetLoginUrl',
69+
[
70+
'context' => 'com_externallogin',
71+
'subject' => $item,
72+
]
73+
);
74+
$event->setArgument('service', Route::_($uri, true));
75+
$dispatcher->dispatch('onGetLoginUrl', $event);
76+
77+
$results = $event->getArgument('result', []);
5878

5979
if (!empty($results)) {
60-
$item->url = $results[0];
80+
$result = is_array($results) ? $results[0] : $results;
81+
$item->url = $result;
6182
} else {
6283
unset($items[$i]);
6384
}
6485
}
6586

66-
return $items;
87+
return array_values($items);
6788
}
6889
}

src/administrator/modules/mod_externallogin_admin/tmpl/alone.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
// No direct access to this file
1616
defined('_JEXEC') or die;
17+
18+
$servers ??= [];
19+
20+
if ($servers === []) {
21+
return;
22+
}
1723
?>
1824
<h4><?php echo $servers[0]->title; ?></h4>
1925
<div class="control-group">

src/administrator/modules/mod_externallogin_admin/tmpl/default.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
use Joomla\CMS\Helper\ModuleHelper;
1414
use Joomla\CMS\HTML\HTMLHelper;
1515
use Joomla\CMS\Router\Route;
16+
use Joomla\Registry\Registry;
1617

1718
// No direct access to this file
1819
defined('_JEXEC') or die;
20+
21+
/** @var Registry $params */
22+
$params ??= new Registry();
23+
$enabled = (bool) ($enabled ?? false);
24+
$count = (int) ($count ?? 0);
1925
?>
2026
<form action="<?php echo Route::_('index.php', true, $params->get('usesecure')); ?>" method="post" id="external-login">
2127
<?php require ModuleHelper::getLayoutPath('mod_externallogin_admin', 'title'); ?>

src/administrator/modules/mod_externallogin_admin/tmpl/disabled.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
* @link https://github.com/akunzai/joomla-external-login
1111
*/
1212

13-
use Joomla\CMS\Language\Text;
14-
1513
// No direct access to this file
1614
defined('_JEXEC') or die;
1715

16+
use Joomla\CMS\Language\Text;
1817

1918
echo Text::_('MOD_EXTERNALLOGIN_ADMIN_DISABLED');

src/administrator/modules/mod_externallogin_admin/tmpl/form.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
// No direct access to this file
1616
defined('_JEXEC') or die;
17+
18+
/** @var object $module */
19+
/** @var array<int, object> $servers */
20+
$module ??= (object) ['id' => 0, 'showtitle' => 0, 'title' => ''];
21+
$servers ??= [];
1722
?>
1823
<label for="mod-server-login-<?php echo $module->id; ?>"><?php echo Text::_('MOD_EXTERNALLOGIN_ADMIN_SERVER_LABEL'); ?></label>
1924
<select id="mod-server-login-<?php echo $module->id; ?>">

src/administrator/modules/mod_externallogin_admin/tmpl/title.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
// No direct access to this file
1414
defined('_JEXEC') or die;
15+
16+
/** @var object $module */
17+
$module ??= (object) ['showtitle' => 0, 'title' => ''];
1518
?>
1619
<?php if ($module->showtitle != 0) : ?>
1720
<h3><?php echo $module->title; ?></h3>

0 commit comments

Comments
 (0)