Fix breadcrumbs to respect showHome, showLast, homeText settings
Breadcrumbs override now reads module params: showHome controls Home item visibility, homeText sets custom Home label, showLast controls whether the current page appears. Bump to 03.09.09. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,31 +10,62 @@
|
|||||||
/**
|
/**
|
||||||
* Default layout override for mod_breadcrumbs.
|
* Default layout override for mod_breadcrumbs.
|
||||||
* Bootstrap 5 breadcrumb with schema.org BreadcrumbList markup.
|
* Bootstrap 5 breadcrumb with schema.org BreadcrumbList markup.
|
||||||
|
* Respects showHome, showLast, homeText module settings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('_JEXEC') or die;
|
defined('_JEXEC') or die;
|
||||||
|
|
||||||
use Joomla\CMS\Factory;
|
use Joomla\CMS\Factory;
|
||||||
use Joomla\CMS\Language\Text;
|
use Joomla\CMS\Language\Text;
|
||||||
|
use Joomla\CMS\Router\Route;
|
||||||
|
use Joomla\CMS\Uri\Uri;
|
||||||
|
|
||||||
Factory::getApplication()->getLanguage()->load('mod_breadcrumbs', JPATH_SITE);
|
Factory::getApplication()->getLanguage()->load('mod_breadcrumbs', JPATH_SITE);
|
||||||
|
|
||||||
$suffix = htmlspecialchars($params->get('moduleclass_sfx', ''), ENT_COMPAT, 'UTF-8');
|
$suffix = htmlspecialchars($params->get('moduleclass_sfx', ''), ENT_COMPAT, 'UTF-8');
|
||||||
$headerTag = htmlspecialchars($params->get('header_tag', 'h3'), ENT_COMPAT, 'UTF-8');
|
$headerTag = htmlspecialchars($params->get('header_tag', 'h3'), ENT_COMPAT, 'UTF-8');
|
||||||
$headerClass = htmlspecialchars($params->get('header_class', ''), ENT_COMPAT, 'UTF-8');
|
$headerClass = htmlspecialchars($params->get('header_class', ''), ENT_COMPAT, 'UTF-8');
|
||||||
|
$showHome = $params->get('showHome', 1);
|
||||||
|
$showLast = $params->get('showLast', 1);
|
||||||
|
$homeText = $params->get('homeText', '') ?: Text::_('MOD_BREADCRUMBS_HOME');
|
||||||
|
|
||||||
|
// Build filtered list respecting module settings
|
||||||
|
$items = [];
|
||||||
|
$count = count($list);
|
||||||
|
|
||||||
|
foreach ($list as $key => $item) {
|
||||||
|
// Skip Home item if showHome is off
|
||||||
|
if ($key === 0 && !$showHome) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace Home text if custom homeText is set
|
||||||
|
if ($key === 0 && $showHome) {
|
||||||
|
$item->name = $homeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip last item if showLast is off
|
||||||
|
if ($key === $count - 1 && !$showLast) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$items[] = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($items)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<nav class="mod-breadcrumbs<?php echo $suffix ? ' ' . $suffix : ''; ?>" aria-label="<?php echo Text::_('MOD_BREADCRUMBS_HERE'); ?>">
|
<nav class="mod-breadcrumbs<?php echo $suffix ? ' ' . $suffix : ''; ?>" aria-label="<?php echo Text::_('MOD_BREADCRUMBS_HERE'); ?>">
|
||||||
<?php if ($module->showtitle) : ?>
|
<?php if ($module->showtitle) : ?>
|
||||||
<<?php echo $headerTag; ?> class="mod-breadcrumbs__title<?php echo $headerClass ? ' ' . $headerClass : ''; ?>"><?php echo $module->title; ?></<?php echo $headerTag; ?>>
|
<<?php echo $headerTag; ?> class="mod-breadcrumbs__title<?php echo $headerClass ? ' ' . $headerClass : ''; ?>"><?php echo $module->title; ?></<?php echo $headerTag; ?>>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<ol class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
|
<ol class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
|
||||||
<?php foreach ($list as $key => $item) : ?>
|
<?php foreach ($items as $key => $item) : ?>
|
||||||
<?php
|
<?php $isLast = ($key === array_key_last($items)); ?>
|
||||||
$isLast = ($key === array_key_last($list));
|
|
||||||
?>
|
|
||||||
<li class="breadcrumb-item<?php echo $isLast ? ' active' : ''; ?>" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"
|
<li class="breadcrumb-item<?php echo $isLast ? ' active' : ''; ?>" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"
|
||||||
<?php echo $isLast ? ' aria-current="page"' : ''; ?>>
|
<?php echo $isLast ? ' aria-current="page"' : ''; ?>>
|
||||||
<?php if (!$isLast && $item->link) : ?>
|
<?php if (!$isLast && !empty($item->link)) : ?>
|
||||||
<a href="<?php echo $item->link; ?>" itemprop="item">
|
<a href="<?php echo $item->link; ?>" itemprop="item">
|
||||||
<span itemprop="name"><?php echo $item->name; ?></span>
|
<span itemprop="name"><?php echo $item->name; ?></span>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
</server>
|
</server>
|
||||||
</updateservers>
|
</updateservers>
|
||||||
<name>MokoCassiopeia</name>
|
<name>MokoCassiopeia</name>
|
||||||
<version>03.09.08</version>
|
<version>03.09.09</version>
|
||||||
<scriptfile>script.php</scriptfile>
|
<scriptfile>script.php</scriptfile>
|
||||||
<creationDate>2026-03-26</creationDate>
|
<creationDate>2026-03-26</creationDate>
|
||||||
<author>Jonathan Miller || Moko Consulting</author>
|
<author>Jonathan Miller || Moko Consulting</author>
|
||||||
|
|||||||
Reference in New Issue
Block a user