Skip to content

Commit f3f2e8d

Browse files
authored
[4.4] Rebuild module Breadcrumbs with new Joomla 4 structure (#40328)
* services * Delete mod_breadcrumbs.php here no longer required, moved * Updated to new structure * Create Dispatcher.php * Create provider.php * Create Default.cy.js * Correction Missing tag * Correction * Delete $data parameter BreadcrumbsHelper has no constructor. * Restore setSeparator function Please restore it and deprecate it * Order functions changed More logical * HTMLHelper Needed for setSeparator * Improve test description In accordance with #40386 * Correction $this->getHome => $this->getHomeItem * not used anymore add text * functionality better description
1 parent 8262060 commit f3f2e8d

File tree

6 files changed

+157
-36
lines changed

6 files changed

+157
-36
lines changed

modules/mod_breadcrumbs/mod_breadcrumbs.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

modules/mod_breadcrumbs/mod_breadcrumbs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<description>MOD_BREADCRUMBS_XML_DESCRIPTION</description>
1212
<namespace path="src">Joomla\Module\Breadcrumbs</namespace>
1313
<files>
14-
<filename module="mod_breadcrumbs">mod_breadcrumbs.php</filename>
14+
<folder module="mod_breadcrumbs">services</folder>
1515
<folder>src</folder>
1616
<folder>tmpl</folder>
1717
</files>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Site
5+
* @subpackage mod_breadcrumbs
6+
*
7+
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
defined('_JEXEC') or die;
12+
13+
use Joomla\CMS\Extension\Service\Provider\HelperFactory;
14+
use Joomla\CMS\Extension\Service\Provider\Module;
15+
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
16+
use Joomla\DI\Container;
17+
use Joomla\DI\ServiceProviderInterface;
18+
19+
/**
20+
* The breadcrumbs module service provider.
21+
*
22+
* @since __DEPLOY_VERSION__
23+
*/
24+
return new class () implements ServiceProviderInterface {
25+
/**
26+
* Registers the service provider with a DI container.
27+
*
28+
* @param Container $container The DI container.
29+
*
30+
* @return void
31+
*
32+
* @since __DEPLOY_VERSION__
33+
*/
34+
public function register(Container $container): void
35+
{
36+
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Breadcrumbs'));
37+
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Breadcrumbs\\Site\\Helper'));
38+
39+
$container->registerServiceProvider(new Module());
40+
}
41+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Site
5+
* @subpackage mod_breadcrumbs
6+
*
7+
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Module\Breadcrumbs\Site\Dispatcher;
12+
13+
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
14+
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
15+
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
16+
17+
// phpcs:disable PSR1.Files.SideEffects
18+
\defined('_JEXEC') or die;
19+
// phpcs:enable PSR1.Files.SideEffects
20+
21+
/**
22+
* Dispatcher class for mod_breadcrumbs
23+
*
24+
* @since __DEPLOY_VERSION__
25+
*/
26+
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
27+
{
28+
use HelperFactoryAwareTrait;
29+
30+
/**
31+
* Returns the layout data.
32+
*
33+
* @return array
34+
*
35+
* @since __DEPLOY_VERSION__
36+
*/
37+
protected function getLayoutData(): array
38+
{
39+
$data = parent::getLayoutData();
40+
41+
$data['list'] = $this->getHelperFactory()->getHelper('BreadcrumbsHelper')->getBreadcrumbs($data['params'], $data['app']);
42+
$data['count'] = count($data['list']);
43+
44+
if (!$data['params']->get('showHome', 1)) {
45+
$data['homeCrumb'] = $this->getHelperFactory()->getHelper('BreadcrumbsHelper')->getHomeItem($data['params'], $data['app']);
46+
}
47+
48+
return $data;
49+
}
50+
}

modules/mod_breadcrumbs/src/Helper/BreadcrumbsHelper.php

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
namespace Joomla\Module\Breadcrumbs\Site\Helper;
1212

1313
use Joomla\CMS\Application\CMSApplication;
14+
use Joomla\CMS\Application\SiteApplication;
1415
use Joomla\CMS\Factory;
1516
use Joomla\CMS\HTML\HTMLHelper;
1617
use Joomla\CMS\Language\Multilanguage;
17-
use Joomla\CMS\Language\Text;
1818
use Joomla\Registry\Registry;
1919

2020
// phpcs:disable PSR1.Files.SideEffects
@@ -31,12 +31,14 @@ class BreadcrumbsHelper
3131
/**
3232
* Retrieve breadcrumb items
3333
*
34-
* @param Registry $params The module parameters
35-
* @param CMSApplication $app The application
34+
* @param Registry $params The module parameters
35+
* @param SiteApplication $app The application
3636
*
3737
* @return array
38+
*
39+
* @since __DEPLOY_VERSION__
3840
*/
39-
public static function getList(Registry $params, CMSApplication $app)
41+
public function getBreadcrumbs(Registry $params, SiteApplication $app): array
4042
{
4143
// Get the PathWay object from the application
4244
$pathway = $app->getPathway();
@@ -53,7 +55,7 @@ public static function getList(Registry $params, CMSApplication $app)
5355
}
5456

5557
if ($params->get('showHome', 1)) {
56-
array_unshift($crumbs, self::getHome($params, $app));
58+
array_unshift($crumbs, $this->getHomeItem($params, $app));
5759
}
5860

5961
return $crumbs;
@@ -62,14 +64,14 @@ public static function getList(Registry $params, CMSApplication $app)
6264
/**
6365
* Retrieve home item (start page)
6466
*
65-
* @param Registry $params The module parameters
66-
* @param CMSApplication $app The application
67+
* @param Registry $params The module parameters
68+
* @param SiteApplication $app The application
6769
*
6870
* @return object
6971
*
70-
* @since 4.2.0
72+
* @since __DEPLOY_VERSION__
7173
*/
72-
public static function getHome(Registry $params, CMSApplication $app)
74+
public function getHomeItem(Registry $params, SiteApplication $app): object
7375
{
7476
$menu = $app->getMenu();
7577

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

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

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

114118
return $_separator;
115119
}
120+
121+
/**
122+
* Retrieve breadcrumb items
123+
*
124+
* @param Registry $params The module parameters
125+
* @param CMSApplication $app The application
126+
*
127+
* @return array
128+
*
129+
* @since 1.5
130+
*
131+
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
132+
* Use the non-static method getBreadcrumbs
133+
* Example: Factory::getApplication()->bootModule('mod_breadcrumbs', 'site')
134+
* ->getHelper('BreadcrumbsHelper')
135+
* ->getBreadcrumbs($params, Factory::getApplication())
136+
*/
137+
public static function getList(Registry $params, CMSApplication $app)
138+
{
139+
return (new self())->getBreadcrumbs($params, Factory::getApplication());
140+
}
141+
142+
/**
143+
* Retrieve home item (start page)
144+
*
145+
* @param Registry $params The module parameters
146+
* @param CMSApplication $app The application
147+
*
148+
* @return object
149+
*
150+
* @since 4.2.0
151+
*
152+
* @deprecated __DEPLOY_VERSION__ will be removed in 6.0
153+
* Use the non-static method getHomeItem
154+
* Example: Factory::getApplication()->bootModule('mod_breadcrumbs', 'site')
155+
* ->getHelper('BreadcrumbsHelper')
156+
* ->getHomeItem($params, Factory::getApplication())
157+
*/
158+
public static function getHome(Registry $params, CMSApplication $app)
159+
{
160+
return (new self())->getHomeItem($params, Factory::getApplication());
161+
}
116162
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe('Test in frondend that the breadcrumbs module', () => {
2+
it('can display the breadcrumb items', () => {
3+
cy.db_createModule({ module: 'mod_breadcrumbs' }).then(() => {
4+
cy.visit('/');
5+
6+
cy.contains('li', 'You are here:');
7+
});
8+
});
9+
});

0 commit comments

Comments
 (0)