Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions administrator/modules/mod_quickicon/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

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;
Expand All @@ -33,6 +34,7 @@
public function register(Container $container)
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Quickicon'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Quickicon\\Administrator\\Helper'));

$container->registerServiceProvider(new Module);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected function getLayoutData()
{
$data = parent::getLayoutData();

$data['buttons'] = QuickIconHelper::getButtons($data['params'], $this->getApplication());
$helper = $this->app->bootModule('mod_quickicon', 'administrator')->getHelper('QuickIconHelper');
$data['buttons'] = $helper->getButtons($data['params'], $this->getApplication());

return $data;
}
Expand Down
38 changes: 19 additions & 19 deletions administrator/modules/mod_quickicon/src/Helper/QuickIconHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
*
* @since 1.6
*/
abstract class QuickIconHelper
class QuickIconHelper
{
/**
* Stack to hold buttons
*
* @var array[]
* @since 1.6
*/
protected static $buttons = array();
protected $buttons = array();

/**
* Helper method to return button list.
Expand All @@ -46,7 +46,7 @@ abstract class QuickIconHelper
*
* @since 1.6
*/
public static function &getButtons(Registry $params, CMSApplication $application = null)
public function getButtons(Registry $params, CMSApplication $application = null)
{
if ($application == null)
{
Expand All @@ -56,12 +56,12 @@ public static function &getButtons(Registry $params, CMSApplication $application
$key = (string) $params;
$context = (string) $params->get('context', 'mod_quickicon');

if (!isset(self::$buttons[$key]))
if (!isset($this->buttons[$key]))
{
// Load mod_quickicon language file in case this method is called before rendering the module
$application->getLanguage()->load('mod_quickicon');

self::$buttons[$key] = [];
$this->buttons[$key] = [];

if ($params->get('show_users'))
{
Expand All @@ -79,7 +79,7 @@ public static function &getButtons(Registry $params, CMSApplication $application
$tmp['ajaxurl'] = 'index.php?option=com_users&task=users.getQuickiconContent&format=json';
}

self::$buttons[$key][] = $tmp;
$this->buttons[$key][] = $tmp;
}

if ($params->get('show_menuitems'))
Expand All @@ -98,7 +98,7 @@ public static function &getButtons(Registry $params, CMSApplication $application
$tmp['ajaxurl'] = 'index.php?option=com_menus&task=items.getQuickiconContent&format=json';
}

self::$buttons[$key][] = $tmp;
$this->buttons[$key][] = $tmp;
}

if ($params->get('show_articles'))
Expand All @@ -117,7 +117,7 @@ public static function &getButtons(Registry $params, CMSApplication $application
$tmp['ajaxurl'] = 'index.php?option=com_content&task=articles.getQuickiconContent&format=json';
}

self::$buttons[$key][] = $tmp;
$this->buttons[$key][] = $tmp;
}

if ($params->get('show_categories'))
Expand All @@ -136,12 +136,12 @@ public static function &getButtons(Registry $params, CMSApplication $application
$tmp['ajaxurl'] = 'index.php?option=com_categories&task=categories.getQuickiconContent&format=json';
}

self::$buttons[$key][] = $tmp;
$this->buttons[$key][] = $tmp;
}

if ($params->get('show_media'))
{
self::$buttons[$key][] = [
$this->buttons[$key][] = [
'image' => 'icon-images',
'link' => Route::_('index.php?option=com_media'),
'name' => 'MOD_QUICKICON_MEDIA_MANAGER',
Expand All @@ -166,7 +166,7 @@ public static function &getButtons(Registry $params, CMSApplication $application
$tmp['ajaxurl'] = 'index.php?option=com_modules&task=modules.getQuickiconContent&format=json';
}

self::$buttons[$key][] = $tmp;
$this->buttons[$key][] = $tmp;
}

if ($params->get('show_plugins'))
Expand All @@ -184,12 +184,12 @@ public static function &getButtons(Registry $params, CMSApplication $application
$tmp['ajaxurl'] = 'index.php?option=com_plugins&task=plugins.getQuickiconContent&format=json';
}

self::$buttons[$key][] = $tmp;
$this->buttons[$key][] = $tmp;
}

if ($params->get('show_template_styles'))
{
self::$buttons[$key][] = [
$this->buttons[$key][] = [
'image' => 'icon-paint-brush',
'link' => Route::_('index.php?option=com_templates&view=styles&client_id=0'),
'name' => 'MOD_QUICKICON_TEMPLATE_STYLES',
Expand All @@ -200,7 +200,7 @@ public static function &getButtons(Registry $params, CMSApplication $application

if ($params->get('show_template_code'))
{
self::$buttons[$key][] = [
$this->buttons[$key][] = [
'image' => 'icon-code',
'link' => Route::_('index.php?option=com_templates&view=templates&client_id=0'),
'name' => 'MOD_QUICKICON_TEMPLATE_CODE',
Expand All @@ -224,7 +224,7 @@ public static function &getButtons(Registry $params, CMSApplication $application
$tmp['ajaxurl'] = 'index.php?option=com_checkin&task=getQuickiconContent&format=json';
}

self::$buttons[$key][] = $tmp;
$this->buttons[$key][] = $tmp;
}

if ($params->get('show_cache'))
Expand All @@ -242,12 +242,12 @@ public static function &getButtons(Registry $params, CMSApplication $application
$tmp['ajaxurl'] = 'index.php?option=com_cache&task=display.getQuickiconContent&format=json';
}

self::$buttons[$key][] = $tmp;
$this->buttons[$key][] = $tmp;
}

if ($params->get('show_global'))
{
self::$buttons[$key][] = [
$this->buttons[$key][] = [
'image' => 'icon-cog',
'link' => Route::_('index.php?option=com_config'),
'name' => 'MOD_QUICKICON_GLOBAL_CONFIGURATION',
Expand Down Expand Up @@ -287,12 +287,12 @@ public static function &getButtons(Registry $params, CMSApplication $application

if (!\is_null($icon['link']) && !\is_null($icon['text']))
{
self::$buttons[$key][] = $icon;
$this->buttons[$key][] = $icon;
}
}
}
}

return self::$buttons[$key];
return $this->buttons[$key];
}
}
11 changes: 9 additions & 2 deletions components/com_ajax/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@

$method = $input->get('method') ?: 'get';

if (is_file($helperFile))
$moduleInstance = $app->bootModule('mod_' . $module, $app->getName());

if ($moduleInstance instanceof \Joomla\CMS\Helper\HelperFactoryInterface && $helper = $moduleInstance->getHelper(substr($class, 3)))
{
$results = method_exists($helper, $method . 'Ajax') ? $helper->{$method . 'Ajax'}() : null;
}

if ($results === null && is_file($helperFile))
{
JLoader::register($class, $helperFile);

Expand Down Expand Up @@ -120,7 +127,7 @@
}
}
// The helper file does not exist
else
elseif ($results === null)
{
$results = new RuntimeException(Text::sprintf('COM_AJAX_FILE_NOT_EXISTS', 'mod_' . $module . '/helper.php'), 404);
}
Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Extension/ExtensionManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Dispatcher\ModuleDispatcherFactory;
use Joomla\CMS\Event\AbstractEvent;
use Joomla\CMS\Helper\HelperFactory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
Expand Down Expand Up @@ -152,7 +153,7 @@ private function loadExtension($type, $extensionName, $extensionPath)
$container->set($type, new LegacyComponent('com_' . $extensionName));
break;
case ModuleInterface::class:
$container->set($type, new Module(new ModuleDispatcherFactory('')));
$container->set($type, new Module(new ModuleDispatcherFactory(''), new HelperFactory('')));
break;
case PluginInterface::class:
list($pluginName, $pluginType) = explode(':', $extensionName);
Expand Down
32 changes: 30 additions & 2 deletions libraries/src/Extension/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Dispatcher\DispatcherInterface;
use Joomla\CMS\Dispatcher\ModuleDispatcherFactoryInterface;
use Joomla\CMS\Helper\HelperFactory;
use Joomla\CMS\Helper\HelperFactoryInterface;
use Joomla\Input\Input;

/**
* Access to module specific services.
*
* @since 4.0.0
*/
class Module implements ModuleInterface
class Module implements ModuleInterface, HelperFactoryInterface
{
/**
* The dispatcher factory.
Expand All @@ -31,16 +33,27 @@ class Module implements ModuleInterface
*/
private $dispatcherFactory;

/**
* The helper factory.
*
* @var HelperFactoryInterface
*
* @since __DEPLOY_VERSION__
*/
private $helperFactory;

/**
* Module constructor.
*
* @param ModuleDispatcherFactoryInterface $dispatcherFactory The dispatcher factory
* @param HelperFactoryInterface $helperFactory The helper factory
*
* @since 4.0.0
*/
public function __construct(ModuleDispatcherFactoryInterface $dispatcherFactory)
public function __construct(ModuleDispatcherFactoryInterface $dispatcherFactory, HelperFactoryInterface $helperFactory)
{
$this->dispatcherFactory = $dispatcherFactory;
$this->helperFactory = $helperFactory;
}

/**
Expand All @@ -58,4 +71,19 @@ public function getDispatcher(\stdClass $module, CMSApplicationInterface $applic
{
return $this->dispatcherFactory->createDispatcher($module, $application, $input);
}

/**
* Returns a helper instance for the given name.
*
* @param string $name The name
* @param array $config The config
*
* @return \stdClass
*
* @since __DEPLOY_VERSION__
*/
public function getHelper(string $name, array $config = [])
{
return $this->helperFactory->getHelper($name, $config);
}
}
64 changes: 64 additions & 0 deletions libraries/src/Extension/Service/Provider/HelperFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Extension\Service\Provider;

\defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Helper\HelperFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

/**
* Service provider for the service helper factory.
*
* @since __DEPLOY_VERSION__
*/
class HelperFactory implements ServiceProviderInterface
{
/**
* The namespace
*
* @var string
*
* @since __DEPLOY_VERSION__
*/
private $namespace;

/**
* HelperFactory constructor.
*
* @param string $namespace The namespace
*
* @since HelperFactory
*/
public function __construct(string $namespace)
{
$this->namespace = $namespace;
}

/**
* 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->set(
HelperFactoryInterface::class,
function (Container $container)
{
return new \Joomla\CMS\Helper\HelperFactory($this->namespace);
}
);
}
}
6 changes: 5 additions & 1 deletion libraries/src/Extension/Service/Provider/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Dispatcher\ModuleDispatcherFactoryInterface;
use Joomla\CMS\Extension\ModuleInterface;
use Joomla\CMS\Helper\HelperFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

Expand All @@ -37,7 +38,10 @@ public function register(Container $container)
ModuleInterface::class,
function (Container $container)
{
return new \Joomla\CMS\Extension\Module($container->get(ModuleDispatcherFactoryInterface::class));
return new \Joomla\CMS\Extension\Module(
$container->get(ModuleDispatcherFactoryInterface::class),
$container->get(HelperFactoryInterface::class)
);
}
);
}
Expand Down
Loading