Skip to content

Commit 5e556fb

Browse files
authored
[5.1] Convert mod_custom to service provider (#42877)
* Convert mod_custom to service provider
1 parent f1524f3 commit 5e556fb

File tree

4 files changed

+91
-26
lines changed

4 files changed

+91
-26
lines changed

administrator/modules/mod_custom/mod_custom.php

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

administrator/modules/mod_custom/mod_custom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
<authorUrl>www.joomla.org</authorUrl>
1010
<version>3.0.0</version>
1111
<description>MOD_CUSTOM_XML_DESCRIPTION</description>
12+
<namespace path="src">Joomla\Module\Custom</namespace>
1213

1314
<customContent />
1415

1516
<files>
16-
<filename module="mod_custom">mod_custom.php</filename>
17+
<folder module="mod_custom">services</folder>
18+
<folder>src</folder>
1719
<folder>tmpl</folder>
1820
</files>
1921
<languages>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage mod_custom
6+
*
7+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
\defined('_JEXEC') or die;
12+
13+
use Joomla\CMS\Extension\Service\Provider\Module;
14+
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
15+
use Joomla\DI\Container;
16+
use Joomla\DI\ServiceProviderInterface;
17+
18+
/**
19+
* The custom module service provider.
20+
*
21+
* @since __DEPLOY_VERSION__
22+
*/
23+
return new class () implements ServiceProviderInterface {
24+
/**
25+
* Registers the service provider with a DI container.
26+
*
27+
* @param Container $container The DI container.
28+
*
29+
* @return void
30+
*
31+
* @since __DEPLOY_VERSION__
32+
*/
33+
public function register(Container $container)
34+
{
35+
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Custom'));
36+
37+
$container->registerServiceProvider(new Module());
38+
}
39+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage mod_custom
6+
*
7+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Module\Custom\Administrator\Dispatcher;
12+
13+
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
14+
use Joomla\CMS\HTML\HTMLHelper;
15+
use Joomla\CMS\Plugin\PluginHelper;
16+
17+
// phpcs:disable PSR1.Files.SideEffects
18+
\defined('_JEXEC') or die;
19+
// phpcs:enable PSR1.Files.SideEffects
20+
21+
/**
22+
* Dispatcher class for mod_custom
23+
*
24+
* @since __DEPLOY_VERSION__
25+
*/
26+
class Dispatcher extends AbstractModuleDispatcher
27+
{
28+
/**
29+
* Returns the layout data.
30+
*
31+
* @return array
32+
*
33+
* @since __DEPLOY_VERSION__
34+
*/
35+
protected function getLayoutData()
36+
{
37+
$data = parent::getLayoutData();
38+
39+
if ($data['params']->def('prepare_content', 1)) {
40+
PluginHelper::importPlugin('content');
41+
$this->module->content = HTMLHelper::_('content.prepare', $this->module->content, '', 'mod_custom.content');
42+
}
43+
44+
// Replace 'images/' to '../images/' when using an image from /images in backend.
45+
$this->module->content = preg_replace('*src\=\"(?!administrator\/)images/*', 'src="../images/', $this->module->content);
46+
47+
return $data;
48+
}
49+
}

0 commit comments

Comments
 (0)