Skip to content

Commit

Permalink
Merge branch '4.4-dev' into providers/plugins/system
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Apr 25, 2023
2 parents e682b78 + f3f2e8d commit fe1388f
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 36 deletions.
25 changes: 0 additions & 25 deletions modules/mod_breadcrumbs/mod_breadcrumbs.php

This file was deleted.

2 changes: 1 addition & 1 deletion modules/mod_breadcrumbs/mod_breadcrumbs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>MOD_BREADCRUMBS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\Breadcrumbs</namespace>
<files>
<filename module="mod_breadcrumbs">mod_breadcrumbs.php</filename>
<folder module="mod_breadcrumbs">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
41 changes: 41 additions & 0 deletions modules/mod_breadcrumbs/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @package Joomla.Site
* @subpackage mod_breadcrumbs
*
* @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 breadcrumbs 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\\Breadcrumbs'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Breadcrumbs\\Site\\Helper'));

$container->registerServiceProvider(new Module());
}
};
50 changes: 50 additions & 0 deletions modules/mod_breadcrumbs/src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* @package Joomla.Site
* @subpackage mod_breadcrumbs
*
* @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\Breadcrumbs\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_breadcrumbs
*
* @since __DEPLOY_VERSION__
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;

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

$data['list'] = $this->getHelperFactory()->getHelper('BreadcrumbsHelper')->getBreadcrumbs($data['params'], $data['app']);
$data['count'] = count($data['list']);

if (!$data['params']->get('showHome', 1)) {
$data['homeCrumb'] = $this->getHelperFactory()->getHelper('BreadcrumbsHelper')->getHomeItem($data['params'], $data['app']);
}

return $data;
}
}
66 changes: 56 additions & 10 deletions modules/mod_breadcrumbs/src/Helper/BreadcrumbsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
namespace Joomla\Module\Breadcrumbs\Site\Helper;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
Expand All @@ -31,12 +31,14 @@ class BreadcrumbsHelper
/**
* Retrieve breadcrumb items
*
* @param Registry $params The module parameters
* @param CMSApplication $app The application
* @param Registry $params The module parameters
* @param SiteApplication $app The application
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getList(Registry $params, CMSApplication $app)
public function getBreadcrumbs(Registry $params, SiteApplication $app): array
{
// Get the PathWay object from the application
$pathway = $app->getPathway();
Expand All @@ -53,7 +55,7 @@ public static function getList(Registry $params, CMSApplication $app)
}

if ($params->get('showHome', 1)) {
array_unshift($crumbs, self::getHome($params, $app));
array_unshift($crumbs, $this->getHomeItem($params, $app));
}

return $crumbs;
Expand All @@ -62,14 +64,14 @@ public static function getList(Registry $params, CMSApplication $app)
/**
* Retrieve home item (start page)
*
* @param Registry $params The module parameters
* @param CMSApplication $app The application
* @param Registry $params The module parameters
* @param SiteApplication $app The application
*
* @return object
*
* @since 4.2.0
* @since __DEPLOY_VERSION__
*/
public static function getHome(Registry $params, CMSApplication $app)
public function getHomeItem(Registry $params, SiteApplication $app): object
{
$menu = $app->getMenu();

Expand All @@ -80,7 +82,7 @@ public static function getHome(Registry $params, CMSApplication $app)
}

$item = new \stdClass();
$item->name = htmlspecialchars($params->get('homeText', Text::_('MOD_BREADCRUMBS_HOME')), ENT_COMPAT, 'UTF-8');
$item->name = htmlspecialchars($params->get('homeText', $app->getLanguage()->_('MOD_BREADCRUMBS_HOME')), ENT_COMPAT, 'UTF-8');
$item->link = 'index.php?Itemid=' . $home->id;

return $item;
Expand All @@ -94,6 +96,8 @@ public static function getHome(Registry $params, CMSApplication $app)
* @return string Separator string
*
* @since 1.5
*
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0 as this function is not used anymore
*/
public static function setSeparator($custom = null)
{
Expand All @@ -113,4 +117,46 @@ public static function setSeparator($custom = null)

return $_separator;
}

/**
* Retrieve breadcrumb items
*
* @param Registry $params The module parameters
* @param CMSApplication $app The application
*
* @return array
*
* @since 1.5
*
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
* Use the non-static method getBreadcrumbs
* Example: Factory::getApplication()->bootModule('mod_breadcrumbs', 'site')
* ->getHelper('BreadcrumbsHelper')
* ->getBreadcrumbs($params, Factory::getApplication())
*/
public static function getList(Registry $params, CMSApplication $app)
{
return (new self())->getBreadcrumbs($params, Factory::getApplication());
}

/**
* Retrieve home item (start page)
*
* @param Registry $params The module parameters
* @param CMSApplication $app The application
*
* @return object
*
* @since 4.2.0
*
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
* Use the non-static method getHomeItem
* Example: Factory::getApplication()->bootModule('mod_breadcrumbs', 'site')
* ->getHelper('BreadcrumbsHelper')
* ->getHomeItem($params, Factory::getApplication())
*/
public static function getHome(Registry $params, CMSApplication $app)
{
return (new self())->getHomeItem($params, Factory::getApplication());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Test in frondend that the breadcrumbs module', () => {
it('can display the breadcrumb items', () => {
cy.db_createModule({ module: 'mod_breadcrumbs' }).then(() => {
cy.visit('/');

cy.contains('li', 'You are here:');
});
});
});

0 comments on commit fe1388f

Please sign in to comment.