Skip to content

Commit

Permalink
[5.1] Convert mod_latestactions to service provider (#42910)
Browse files Browse the repository at this point in the history
  • Loading branch information
joomlaweby committed Feb 29, 2024
1 parent 8da0b7c commit faa4779
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 32 deletions.
27 changes: 0 additions & 27 deletions administrator/modules/mod_latestactions/mod_latestactions.php

This file was deleted.

Expand Up @@ -11,7 +11,7 @@
<description>MOD_LATESTACTIONS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\LatestActions</namespace>
<files>
<filename module="mod_latestactions">mod_latestactions.php</filename>
<folder module="mod_latestactions">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
41 changes: 41 additions & 0 deletions administrator/modules/mod_latestactions/services/provider.php
@@ -0,0 +1,41 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage mod_latestactions
*
* @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 latest actions 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\\LatestActions'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\LatestActions\\Administrator\\Helper'));

$container->registerServiceProvider(new Module());
}
};
@@ -0,0 +1,65 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage mod_latestactions
*
* @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\LatestActions\Administrator\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_latestactions
*
* @since __DEPLOY_VERSION__
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;

/**
* Runs the dispatcher.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function dispatch()
{
if (!$this->getApplication()->getIdentity()->authorise('core.admin')) {
return;
}

parent::dispatch();
}

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

$data['list'] = $this->getHelperFactory()->getHelper('LatestActionsHelper')->getActions($data['params']);

if ($data['params']->get('automatic_title', 0)) {
$this->module->title = $this->getHelperFactory()->getHelper('LatestActionsHelper')->getModuleTitle($data['params']);
}

return $data;
}
}
Expand Up @@ -24,7 +24,7 @@
*
* @since 3.9.0
*/
abstract class LatestActionsHelper
class LatestActionsHelper
{
/**
* Get a list of logged actions.
Expand All @@ -33,11 +33,11 @@ abstract class LatestActionsHelper
*
* @return mixed An array of action logs, or false on error.
*
* @since 3.9.1
* @since __DEPLOY_VERSION__
*
* @throws \Exception
*/
public static function getList(&$params)
public function getActions(&$params)
{
/** @var \Joomla\Component\Actionlogs\Administrator\Model\ActionlogsModel $model */
$model = Factory::getApplication()->bootComponent('com_actionlogs')->getMVCFactory()
Expand All @@ -61,6 +61,20 @@ public static function getList(&$params)
return $rows;
}

/**
* Get the alternate title for the module
*
* @param Registry $params The module parameters.
*
* @return string The alternate title for the module.
*
* @since __DEPLOY_VERSION__
*/
public function getModuleTitle($params)
{
return Text::plural('MOD_LATESTACTIONS_TITLE', $params->get('count', 5));
}

/**
* Get the alternate title for the module
*
Expand All @@ -69,9 +83,37 @@ public static function getList(&$params)
* @return string The alternate title for the module.
*
* @since 3.9.1
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getModuleTitle
* Example: Factory::getApplication()->bootModule('mod_latestactions', 'administrator')
* ->getHelper('LatestActionsHelper')
* ->getModuleTitle($params)
*/
public static function getTitle($params)
{
return Text::plural('MOD_LATESTACTIONS_TITLE', $params->get('count', 5));
return (new self())->getModuleTitle($params);
}

/**
* Get a list of logged actions.
*
* @param Registry &$params The module parameters.
*
* @return mixed An array of action logs, or false on error.
*
* @since 3.9.1
*
* @throws \Exception
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getActions
* Example: Factory::getApplication()->bootModule('mod_latestactions', 'administrator')
* ->getHelper('LatestActionsHelper')
* ->getActions($params)
*/
public static function getList(&$params)
{
return (new self())->getActions($params);
}
}

0 comments on commit faa4779

Please sign in to comment.