Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Convert mod_wrapper to service provider #42792

Merged
merged 7 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 0 additions & 27 deletions modules/mod_wrapper/mod_wrapper.php

This file was deleted.

2 changes: 1 addition & 1 deletion modules/mod_wrapper/mod_wrapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>MOD_WRAPPER_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\Wrapper</namespace>
<files>
<filename module="mod_wrapper">mod_wrapper.php</filename>
<folder module="mod_wrapper">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
41 changes: 41 additions & 0 deletions modules/mod_wrapper/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @package Joomla.Site
* @subpackage mod_wrapper
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @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 wrapper 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\\Wrapper'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Wrapper\\Site\\Helper'));

$container->registerServiceProvider(new Module());
}
};
54 changes: 54 additions & 0 deletions modules/mod_wrapper/src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* @package Joomla.Site
* @subpackage mod_wrapper
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Module\Wrapper\Site\Dispatcher;

use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Dispatcher class for mod_wrapper
*
* @since __DEPLOY_VERSION__
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;

/**
* Returns the layout data.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();

$params = $this->getHelperFactory()->getHelper('WrapperHelper')->getParamsWrapper($data['params'], $this->getApplication());

$data['load'] = $params->get('load');
$data['url'] = htmlspecialchars($params->get('url', ''), ENT_COMPAT, 'UTF-8');
$data['target'] = htmlspecialchars($params->get('target', ''), ENT_COMPAT, 'UTF-8');
$data['width'] = htmlspecialchars($params->get('width', ''), ENT_COMPAT, 'UTF-8');
$data['height'] = htmlspecialchars($params->get('height', ''), ENT_COMPAT, 'UTF-8');
$data['ititle'] = $this->module->title;
$data['id'] = $this->module->id;
$data['lazyloading'] = $params->get('lazyloading', 'lazy');

return $data;
}
}
33 changes: 28 additions & 5 deletions modules/mod_wrapper/src/Helper/WrapperHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

namespace Joomla\Module\Wrapper\Site\Helper;

use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Factory;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -26,13 +28,14 @@ class WrapperHelper
/**
* Gets the parameters for the wrapper
*
* @param mixed &$params The parameters set in the administrator section
* @param Registry $params The module parameters.
* @param SiteApplication $app The current application.
*
* @return mixed &$params The modified parameters
* @return mixed $params The modified parameters
*
* @since 1.5
* @since __DEPLOY_VERSION__
*/
public static function getParams(&$params)
public function getParamsWrapper(Registry $params, SiteApplication $app)
{
$params->def('url', '');
$params->def('scrolling', 'auto');
Expand All @@ -48,7 +51,7 @@ public static function getParams(&$params)
// Adds 'http://' if none is set
if (strpos($url, '/') === 0) {
// Relative URL in component. use server http_host.
$url = 'http://' . Factory::getApplication()->getInput()->server->get('HTTP_HOST') . $url;
$url = 'http://' . $app->getInput()->server->get('HTTP_HOST') . $url;
} elseif (strpos($url, 'http') === false && strpos($url, 'https') === false) {
$url = 'http://' . $url;
}
Expand All @@ -66,4 +69,24 @@ public static function getParams(&$params)

return $params;
}

/**
* Gets the parameters for the wrapper
*
* @param mixed &$params The parameters set in the administrator section
*
* @return mixed &$params The modified parameters
*
* @since 1.5
*
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
* Use the non-static method getParamsWrapper
* Example: Factory::getApplication()->bootModule('mod_wrapper', 'site')
* ->getHelper('WrapperHelper')
* ->getParamsWrapper($params, Factory::getApplication())
*/
public static function getParams(&$params)
{
return (new self())->getParamsWrapper($params, Factory::getApplication());
}
}