mirror of
https://github.com/joomla-extensions/weblinks.git
synced 2024-09-28 04:59:04 +00:00
Convert mod_weblinks module to use services provider
This commit is contained in:
parent
8d928181e9
commit
35ab8a7048
@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @package Joomla.Administrator
|
|
||||||
* @subpackage Weblinks
|
|
||||||
*
|
|
||||||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
|
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
defined('_JEXEC') or die;
|
|
||||||
|
|
||||||
use Joomla\CMS\Helper\ModuleHelper;
|
|
||||||
use Joomla\Module\Weblinks\Site\Helper\WeblinksHelper;
|
|
||||||
|
|
||||||
$list = WeblinksHelper::getList($params, $app);
|
|
||||||
|
|
||||||
if (empty($list))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
|
|
||||||
|
|
||||||
require ModuleHelper::getLayoutPath('mod_weblinks', $params->get('layout', 'default'));
|
|
@ -12,7 +12,6 @@
|
|||||||
<namespace path="src">Joomla\Module\Weblinks</namespace>
|
<namespace path="src">Joomla\Module\Weblinks</namespace>
|
||||||
<files>
|
<files>
|
||||||
##MODULE_FILES##
|
##MODULE_FILES##
|
||||||
<file module="mod_weblinks">mod_weblinks.php</file>
|
|
||||||
</files>
|
</files>
|
||||||
<languages folder="language">
|
<languages folder="language">
|
||||||
##LANGUAGE_FILES##
|
##LANGUAGE_FILES##
|
||||||
|
41
src/modules/mod_weblinks/services/provider.php
Normal file
41
src/modules/mod_weblinks/services/provider.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Joomla.Site
|
||||||
|
* @subpackage mod_weblinks
|
||||||
|
*
|
||||||
|
* @copyright (C) 2022 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 weblinks module services 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\\Weblinks'));
|
||||||
|
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Weblinks\\Site\\Helper'));
|
||||||
|
|
||||||
|
$container->registerServiceProvider(new Module());
|
||||||
|
}
|
||||||
|
};
|
50
src/modules/mod_weblinks/src/Dispatcher/Dispatcher.php
Normal file
50
src/modules/mod_weblinks/src/Dispatcher/Dispatcher.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Joomla.Site
|
||||||
|
* @subpackage mod_weblinks
|
||||||
|
*
|
||||||
|
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
|
||||||
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Joomla\Module\Weblinks\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_weblinks
|
||||||
|
*
|
||||||
|
* @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();
|
||||||
|
|
||||||
|
$data['list'] = $this->getHelperFactory()->getHelper('WeblinksHelper')->getWeblinks(
|
||||||
|
$data['params'],
|
||||||
|
$this->getApplication()
|
||||||
|
);
|
||||||
|
|
||||||
|
$data['moduleclass_sfx'] = htmlspecialchars($data['params']->get('moduleclass_sfx', ''));
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
@ -29,14 +29,13 @@ class WeblinksHelper
|
|||||||
* @param Registry $params The module parameters
|
* @param Registry $params The module parameters
|
||||||
* @param CMSApplicationInterface $app The application
|
* @param CMSApplicationInterface $app The application
|
||||||
*
|
*
|
||||||
* @return mixed Null if no weblinks based on input parameters else an array containing all the weblinks.
|
* @return array Array containing all the weblinks.
|
||||||
*
|
*
|
||||||
* @since 1.5
|
* @since __DEPLOY_VERSION__
|
||||||
**/
|
**/
|
||||||
public static function getList($params, $app)
|
public function getWeblinks($params, $app)
|
||||||
{
|
{
|
||||||
// @var \Joomla\Component\Weblinks\Site\Model\CategoryModel $model
|
// @var \Joomla\Component\Weblinks\Site\Model\CategoryModel $model
|
||||||
|
|
||||||
$model = $app->bootComponent('com_weblinks')->getMVCFactory()
|
$model = $app->bootComponent('com_weblinks')->getMVCFactory()
|
||||||
->createModel('Category', 'Site', ['ignore_request' => true]);
|
->createModel('Category', 'Site', ['ignore_request' => true]);
|
||||||
|
|
||||||
@ -73,7 +72,7 @@ class WeblinksHelper
|
|||||||
$case_when1 .= $query->charLength('a.alias', '!=', '0');
|
$case_when1 .= $query->charLength('a.alias', '!=', '0');
|
||||||
$case_when1 .= ' THEN ';
|
$case_when1 .= ' THEN ';
|
||||||
$a_id = $query->castAs('CHAR', 'a.id');
|
$a_id = $query->castAs('CHAR', 'a.id');
|
||||||
$case_when1 .= $query->concatenate(array($a_id, 'a.alias'), ':');
|
$case_when1 .= $query->concatenate([$a_id, 'a.alias'], ':');
|
||||||
$case_when1 .= ' ELSE ';
|
$case_when1 .= ' ELSE ';
|
||||||
$case_when1 .= $a_id . ' END as slug';
|
$case_when1 .= $a_id . ' END as slug';
|
||||||
|
|
||||||
@ -81,7 +80,7 @@ class WeblinksHelper
|
|||||||
$case_when2 .= $query->charLength('c.alias', '!=', '0');
|
$case_when2 .= $query->charLength('c.alias', '!=', '0');
|
||||||
$case_when2 .= ' THEN ';
|
$case_when2 .= ' THEN ';
|
||||||
$c_id = $query->castAs('CHAR', 'c.id');
|
$c_id = $query->castAs('CHAR', 'c.id');
|
||||||
$case_when2 .= $query->concatenate(array($c_id, 'c.alias'), ':');
|
$case_when2 .= $query->concatenate([$c_id, 'c.alias'], ':');
|
||||||
$case_when2 .= ' ELSE ';
|
$case_when2 .= ' ELSE ';
|
||||||
$case_when2 .= $c_id . ' END as catslug';
|
$case_when2 .= $c_id . ' END as catslug';
|
||||||
|
|
||||||
@ -120,4 +119,21 @@ class WeblinksHelper
|
|||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve list of weblinks
|
||||||
|
*
|
||||||
|
* @param Registry $params The module parameters
|
||||||
|
* @param CMSApplicationInterface $app The application
|
||||||
|
*
|
||||||
|
* @return mixed Null if no weblinks based on input parameters else an array containing all the weblinks.
|
||||||
|
*
|
||||||
|
* @since 1.5
|
||||||
|
*
|
||||||
|
* @deprecated 5.0 Use the none static function getWeblinks
|
||||||
|
**/
|
||||||
|
public static function getList($params, $app)
|
||||||
|
{
|
||||||
|
return (new self())->getWeblinks($params, $app);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user