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_banners to service provider #42214

Merged
merged 4 commits into from Jan 24, 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
25 changes: 0 additions & 25 deletions modules/mod_banners/mod_banners.php

This file was deleted.

2 changes: 1 addition & 1 deletion modules/mod_banners/mod_banners.xml
Expand Up @@ -11,7 +11,7 @@
<description>MOD_BANNERS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\Banners</namespace>
<files>
<filename module="mod_banners">mod_banners.php</filename>
<folder module="mod_banners">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
41 changes: 41 additions & 0 deletions modules/mod_banners/services/provider.php
@@ -0,0 +1,41 @@
<?php

/**
* @package Joomla.Site
* @subpackage mod_banners
*
* @copyright (C) 2023 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 banners 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): void
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Banners'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Banners\\Site\\Helper'));

$container->registerServiceProvider(new Module());
}
};
50 changes: 50 additions & 0 deletions modules/mod_banners/src/Dispatcher/Dispatcher.php
@@ -0,0 +1,50 @@
<?php

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

namespace Joomla\Module\Banners\Site\Dispatcher;

use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
use Joomla\Component\Banners\Administrator\Helper\BannersHelper as BannersComponentHelper;

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

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

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

$data = parent::getLayoutData();

$data['headerText'] = trim($data['params']->get('header_text', ''));
$data['footerText'] = trim($data['params']->get('footer_text', ''));
$data['list'] = $this->getHelperFactory()->getHelper('BannersHelper')->getBanners($data['params'], $this->getApplication());

return $data;
}
}
30 changes: 28 additions & 2 deletions modules/mod_banners/src/Helper/BannersHelper.php
Expand Up @@ -31,13 +31,17 @@ class BannersHelper
* Retrieve list of banners
*
* @param Registry $params The module parameters
* @param BannersModel $model The model
* @param CMSApplication $app The application
*
* @return mixed
heelc29 marked this conversation as resolved.
Show resolved Hide resolved
*
* @since __DEPLOY_VERSION__
*/
public static function getList(Registry $params, BannersModel $model, CMSApplication $app)
public function getBanners(Registry $params, CMSApplication $app)
{
/** @var BannersModel $model */
$model = $app->bootComponent('com_banners')->getMVCFactory()->createModel('Banners', 'Site', ['ignore_request' => true]);

$keywords = explode(',', $app->getDocument()->getMetaData('keywords'));
$config = ComponentHelper::getParams('com_banners');

Expand All @@ -60,4 +64,26 @@ public static function getList(Registry $params, BannersModel $model, CMSApplica

return $banners;
}

/**
* Retrieve list of banners
*
* @param Registry $params The module parameters
* @param BannersModel $model The model
* @param CMSApplication $app The application
*
* @return mixed
*
* @since 1.5
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getBanners
* Example: Factory::getApplication()->bootModule('mod_banners', 'site')
* ->getHelper('BannersHelper')
* ->getBanners($params, Factory::getApplication())
*/
public static function getList(Registry $params, BannersModel $model, CMSApplication $app)
{
return (new self())->getBanners($params, $app);
}
}