Skip to content

fix(breadcrumb): default to the module being served, not the library folder - #23

Merged
mambax7 merged 2 commits into
XOOPS:masterfrom
mambax7:fix/breadcrumb-default-dirname
Nov 22, 2026
Merged

mambax7 merged 2 commits into
XOOPS:masterfrom
mambax7:fix/breadcrumb-default-dirname

Conversation

@mambax7

@mambax7 mambax7 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Common\Breadcrumb created without a module name (new Breadcrumb()) uses the module being
    served for its default template <dirname>_common_breadcrumb.tpl.
  • It used to take the library's own folder name, so the page failed with
    Unable to load 'db:moduletools_common_breadcrumb.tpl'.
  • A name passed to the constructor still wins; with no module being served, the library folder
    name is kept as before.

Validation

  • composer validate --strict
  • composer test
  • composer analyse

New tests/Common/BreadcrumbTest.php (3 tests). Full suite on PHP 8.2, 8.3, 8.4, 8.5 and 8.6:
191 tests, 25 skipped, no failures. composer qa passes.

Notes

  • No public API change.
  • tests/fixtures/core-stubs.php gains what the new test needs from the core.

Summary by Sourcery

Correct Common\Breadcrumb template selection so pages use the served module’s breadcrumb template by default.

Bug Fixes:

  • Make Common\Breadcrumb default to the module being served when no directory name is provided, while preserving explicit names and the library-folder fallback when no module is active.
  • Treat a directory name of 0 as an explicit value rather than as missing.

Documentation:

  • Document the updated default behavior and when callers should continue passing an explicit module directory.

Tests:

  • Add coverage for module-based defaults, explicit directory and template precedence, zero and empty directory names, and the no-module fallback.

Summary by CodeRabbit

  • Bug Fixes
    • Breadcrumbs now use the active module’s directory when no directory is provided or the supplied value is empty. If no module is active, they use the library’s directory instead.
    • A non-empty supplied directory continues to be represented by its final directory name.
    • The default breadcrumb template continues to follow the resulting directory name.

Copilot AI balanced review requested due to automatic review settings November 22, 2026 01:25
@sourcery-ai

sourcery-ai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Select the active module’s dirname for the default breadcrumb template when no dirname is supplied, while preserving explicit names and the library-folder fallback; the helper comment documents this behavior.

  • src/Common/Breadcrumb.php L45, L85-97

Documentation

Record the breadcrumb default change in the changelog and explain when callers should still pass a dirname in the migration guide.

  • CHANGELOG.md L9-14
  • docs/migrating-a-module.md L120-122

Tests

Cover active-module selection, explicit and empty dirnames, the zero dirname, template override, and the no-module fallback, with a core stub to support those cases.

  • tests/Common/BreadcrumbTest.php L1-84
  • tests/fixtures/core-stubs.php L45-59

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The breadcrumb constructor now defaults to the active module’s directory when available. If no active module exists, it uses the library folder name. Explicit directory values continue to be reduced to their basename.

Changes

Breadcrumb directory defaults

Layer / File(s) Summary
Select the default directory
src/Common/Breadcrumb.php
currentModuleDirname() returns the active module’s dirname, or the library folder name when no XoopsModule is active. The constructor uses this value when no directory is supplied and continues to derive the default template from the resulting directory name.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to d10a4

Breadcrumb now uses the module being served for its default template name, which fixes template-load failures. The behavior change is documented and tested. No concrete merge risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title states the main change: the Breadcrumb default template now follows the module being served instead of the library folder name. The raw summary confirms this change in src/Common/Breadcrumb.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: the Breadcrumb default template now follows the module being served instead of the library folder name. The raw summary confirms this change in src/Common/Breadcrumb.php, where the constructor uses the active module's dirname and falls back to the library folder name. The title is specific, concise, and in a conventional commit format.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

PHPStan (2.3.5)

PHPStan was skipped because the config uses disallowed bootstrapFiles or bootstrapFile directives.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5208a4a and d10a4b6.

Files ignored due to path filters: 3

  • CHANGELOG.md is excluded by !**/*.md
  • docs/migrating-a-module.md is excluded by !docs/**, !**/*.md
  • tests/Common/BreadcrumbTest.php is excluded by !tests/**
Files selected for processing: 1

  • src/Common/Breadcrumb.php

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@gitar-bot

gitar-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Gitar is working

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

Gitar

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/Common/Breadcrumb.php" line_range="45" />
<code_context>

     public function __construct(?string $dirname = null, ?string $template = null)
     {
-        $this->dirname  = $dirname ? basename($dirname) : \basename(\dirname(__DIR__, 2));
+        $this->dirname  = $dirname ? basename($dirname) : self::currentModuleDirname();
         $this->template = $template ?: $this->dirname . '_common_breadcrumb.tpl';
</code_context>
<issue_to_address>
**Numeric module name is ignored**

When the caller passes `'0'` as the dirname while another module is being served, the truthiness check treats the explicit dirname `'0'` as absent, so `currentModuleDirname()` selects the served module instead and the breadcrumb uses the wrong template.

Distinguish null or an empty dirname from a non-empty value such as `'0'` instead of testing truthiness.
</issue_to_address>

### Comment 2
<location path="tests/Common/BreadcrumbTest.php" line_range="34" />
<code_context>
+    {
+        $GLOBALS['xoopsModule'] = new \XoopsModule('tag');
+
+        self::assertSame('tag', (new Breadcrumb())->dirname);
+    }
+
</code_context>
<issue_to_address>
**Default template can remain wrong**

When the constructor derives `dirname` from `xoopsModule` but fails to derive the default template from it, `testWithoutADirnameItTakesTheModuleBeingServed()` checks only the public `dirname` at line 34. The constructor can set that to `tag` while still selecting `moduletools_common_breadcrumb.tpl`, and this test passes although rendering fetches the wrong template.

Assert that rendering or the selected template uses `tag_common_breadcrumb.tpl` for the module-based default.
</issue_to_address>

### Comment 3
<location path="src/Common/Breadcrumb.php" line_range="45" />
<code_context>
     public function __construct(?string $dirname = null, ?string $template = null)
     {
-        $this->dirname  = $dirname ? basename($dirname) : \basename(\dirname(__DIR__, 2));
+        $this->dirname  = $dirname ? basename($dirname) : self::currentModuleDirname();
         $this->template = $template ?: $this->dirname . '_common_breadcrumb.tpl';
     }
</code_context>
<issue_to_address>
**Migration guide gives obsolete advice**

`docs/migrating-a-module.md` still says “The library classes cannot guess your dirname” and tells users to replace `new Breadcrumb()` with `new Breadcrumb($helper->dirname())`, although this default now resolves the served module. Consumers following the guide get the right template, but are told the argument is required when it is no longer needed.

Update the migration guide to say Breadcrumb can infer the served module and that passing `$helper->dirname()` remains an explicit option.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/Common/Breadcrumb.php:45, tests/Common/BreadcrumbTest.php:34


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/Common/Breadcrumb.php Resolved
Comment thread tests/Common/BreadcrumbTest.php Resolved
Comment thread src/Common/Breadcrumb.php Resolved
@sonarqubecloud

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@mambax7
mambax7 merged commit 4bcb122 into XOOPS:master Nov 22, 2026
8 checks passed
@mambax7 mambax7 mentioned this pull request Nov 22, 2026
3 tasks done
@mambax7
mambax7 deleted the fix/breadcrumb-default-dirname branch November 22, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants