Skip to content

Commit 169218b

Browse files
authored
[5.1] Convert mod_wrapper to service provider (#42792)
1 parent c044810 commit 169218b

File tree

5 files changed

+124
-33
lines changed

5 files changed

+124
-33
lines changed

modules/mod_wrapper/mod_wrapper.php

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

modules/mod_wrapper/mod_wrapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<description>MOD_WRAPPER_XML_DESCRIPTION</description>
1212
<namespace path="src">Joomla\Module\Wrapper</namespace>
1313
<files>
14-
<filename module="mod_wrapper">mod_wrapper.php</filename>
14+
<folder module="mod_wrapper">services</folder>
1515
<folder>src</folder>
1616
<folder>tmpl</folder>
1717
</files>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Site
5+
* @subpackage mod_wrapper
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\HelperFactory;
14+
use Joomla\CMS\Extension\Service\Provider\Module;
15+
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
16+
use Joomla\DI\Container;
17+
use Joomla\DI\ServiceProviderInterface;
18+
19+
/**
20+
* The wrapper module service provider.
21+
*
22+
* @since __DEPLOY_VERSION__
23+
*/
24+
return new class () implements ServiceProviderInterface {
25+
/**
26+
* Registers the service provider with a DI container.
27+
*
28+
* @param Container $container The DI container.
29+
*
30+
* @return void
31+
*
32+
* @since __DEPLOY_VERSION__
33+
*/
34+
public function register(Container $container)
35+
{
36+
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Wrapper'));
37+
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Wrapper\\Site\\Helper'));
38+
39+
$container->registerServiceProvider(new Module());
40+
}
41+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Site
5+
* @subpackage mod_wrapper
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\Wrapper\Site\Dispatcher;
12+
13+
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
14+
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
15+
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
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_wrapper
23+
*
24+
* @since __DEPLOY_VERSION__
25+
*/
26+
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
27+
{
28+
use HelperFactoryAwareTrait;
29+
30+
/**
31+
* Returns the layout data.
32+
*
33+
* @return array
34+
*
35+
* @since __DEPLOY_VERSION__
36+
*/
37+
protected function getLayoutData()
38+
{
39+
$data = parent::getLayoutData();
40+
41+
$params = $this->getHelperFactory()->getHelper('WrapperHelper')->getParamsWrapper($data['params'], $this->getApplication());
42+
43+
$data['load'] = $params->get('load');
44+
$data['url'] = htmlspecialchars($params->get('url', ''), ENT_COMPAT, 'UTF-8');
45+
$data['target'] = htmlspecialchars($params->get('target', ''), ENT_COMPAT, 'UTF-8');
46+
$data['width'] = htmlspecialchars($params->get('width', ''), ENT_COMPAT, 'UTF-8');
47+
$data['height'] = htmlspecialchars($params->get('height', ''), ENT_COMPAT, 'UTF-8');
48+
$data['ititle'] = $this->module->title;
49+
$data['id'] = $this->module->id;
50+
$data['lazyloading'] = $params->get('lazyloading', 'lazy');
51+
52+
return $data;
53+
}
54+
}

modules/mod_wrapper/src/Helper/WrapperHelper.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
namespace Joomla\Module\Wrapper\Site\Helper;
1212

13+
use Joomla\CMS\Application\SiteApplication;
1314
use Joomla\CMS\Factory;
15+
use Joomla\Registry\Registry;
1416

1517
// phpcs:disable PSR1.Files.SideEffects
1618
\defined('_JEXEC') or die;
@@ -26,13 +28,14 @@ class WrapperHelper
2628
/**
2729
* Gets the parameters for the wrapper
2830
*
29-
* @param mixed &$params The parameters set in the administrator section
31+
* @param Registry $params The module parameters.
32+
* @param SiteApplication $app The current application.
3033
*
31-
* @return mixed &$params The modified parameters
34+
* @return mixed $params The modified parameters
3235
*
33-
* @since 1.5
36+
* @since __DEPLOY_VERSION__
3437
*/
35-
public static function getParams(&$params)
38+
public function getParamsWrapper(Registry $params, SiteApplication $app)
3639
{
3740
$params->def('url', '');
3841
$params->def('scrolling', 'auto');
@@ -48,7 +51,7 @@ public static function getParams(&$params)
4851
// Adds 'http://' if none is set
4952
if (strpos($url, '/') === 0) {
5053
// Relative URL in component. use server http_host.
51-
$url = 'http://' . Factory::getApplication()->getInput()->server->get('HTTP_HOST') . $url;
54+
$url = 'http://' . $app->getInput()->server->get('HTTP_HOST') . $url;
5255
} elseif (strpos($url, 'http') === false && strpos($url, 'https') === false) {
5356
$url = 'http://' . $url;
5457
}
@@ -66,4 +69,24 @@ public static function getParams(&$params)
6669

6770
return $params;
6871
}
72+
73+
/**
74+
* Gets the parameters for the wrapper
75+
*
76+
* @param mixed &$params The parameters set in the administrator section
77+
*
78+
* @return mixed &$params The modified parameters
79+
*
80+
* @since 1.5
81+
*
82+
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
83+
* Use the non-static method getParamsWrapper
84+
* Example: Factory::getApplication()->bootModule('mod_wrapper', 'site')
85+
* ->getHelper('WrapperHelper')
86+
* ->getParamsWrapper($params, Factory::getApplication())
87+
*/
88+
public static function getParams(&$params)
89+
{
90+
return (new self())->getParamsWrapper($params, Factory::getApplication());
91+
}
6992
}

0 commit comments

Comments
 (0)