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

[4.2] Convert mod_articles_latest to new structure #37947

Merged
merged 4 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 0 additions & 18 deletions modules/mod_articles_latest/mod_articles_latest.php

This file was deleted.

2 changes: 1 addition & 1 deletion modules/mod_articles_latest/mod_articles_latest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>MOD_LATEST_NEWS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\ArticlesLatest</namespace>
<files>
<filename module="mod_articles_latest">mod_articles_latest.php</filename>
<folder module="mod_articles_latest">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
41 changes: 41 additions & 0 deletions modules/mod_articles_latest/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage mod_articles_latest
*
* @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 article latest module service provider.
*
* @since 4.2.0
*/
return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.2.0
*/
public function register(Container $container)
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\ArticlesLatest'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\ArticlesLatest\\Site\\Helper'));

$container->registerServiceProvider(new Module);
}
};
42 changes: 42 additions & 0 deletions modules/mod_articles_latest/src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_articles_latest
*
* @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\ArticlesLatest\Site\Dispatcher;

\defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;

/**
* Dispatcher class for mod_articles_latest
*
* @since 4.2.0
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;

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

$data['list'] = $this->getHelperFactory()->getHelper('ArticlesLatestHelper')->getArticles($data['params'], $this->getApplication());

return $data;
}
}
38 changes: 30 additions & 8 deletions modules/mod_articles_latest/src/Helper/ArticlesLatestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
\defined('_JEXEC') or die;

use Joomla\CMS\Access\Access;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Helper\RouteHelper;
use Joomla\Component\Content\Site\Model\ArticlesModel;
use Joomla\Database\DatabaseAwareInterface;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;

Expand All @@ -25,8 +28,9 @@
*
* @since 1.6
*/
abstract class ArticlesLatestHelper
class ArticlesLatestHelper implements DatabaseAwareInterface
{
use DatabaseAwareTrait;
/**
* Retrieve a list of article
*
Expand All @@ -35,18 +39,19 @@ abstract class ArticlesLatestHelper
*
* @return mixed
*
* @since 1.6
* @since 4.2.0
*/
public static function getList(Registry $params, ArticlesModel $model)
public function getArticles(Registry $params, SiteApplication $app)
{
// Get the Dbo and User object
$db = Factory::getDbo();
$user = Factory::getUser();
$db = $this->getDatabase();
$user = $app->getIdentity();

/** @var ArticlesModel $model */
$model = $app->bootComponent('com_content')->getMVCFactory()->createModel('Articles', 'Site', ['ignore_request' => true]);

// Set application parameters in model
$app = Factory::getApplication();
$appParams = $app->getParams();
$model->setState('params', $appParams);
$model->setState('params', $app->getParams());

$model->setState('list.start', 0);
$model->setState('filter.published', 1);
Expand Down Expand Up @@ -146,4 +151,21 @@ public static function getList(Registry $params, ArticlesModel $model)

return $items;
}

/**
* Retrieve a list of article
richard67 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param Registry $params The module parameters.
* @param ArticlesModel $model The model.
*
* @return mixed
*
* @since 1.6
*
* @deprecated 5.0 Use the none static function getArticles
*/
public static function getList(Registry $params, ArticlesModel $model)
{
return (new self)->getArticles($params, Factory::getApplication());
}
}