Skip to content

Commit

Permalink
[5.1] Convert mod_banners to service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
heelc29 committed Oct 24, 2023
1 parent 6d923f5 commit 57e0557
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 28 deletions.
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
*
* @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);
}
}

0 comments on commit 57e0557

Please sign in to comment.