Repository navigation
fix(breadcrumb): default to the module being served, not the library folder - #23
Conversation
Reviewer's GuideImplementationSelect 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.
DocumentationRecord the breadcrumb default change in the changelog and explain when callers should still pass a dirname in the migration guide.
TestsCover 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.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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.
|
No actionable comments were generated in the recent review. WalkthroughThe 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. ChangesBreadcrumb directory defaults
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk:
|
There was a problem hiding this comment.
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
… template, update the migration guide
|



Summary
Common\Breadcrumbcreated without a module name (new Breadcrumb()) uses the module beingserved for its default template
<dirname>_common_breadcrumb.tpl.Unable to load 'db:moduletools_common_breadcrumb.tpl'.name is kept as before.
Validation
composer validate --strictcomposer testcomposer analyseNew
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 qapasses.Notes
tests/fixtures/core-stubs.phpgains what the new test needs from the core.Summary by Sourcery
Correct
Common\Breadcrumbtemplate selection so pages use the served module’s breadcrumb template by default.Bug Fixes:
Common\Breadcrumbdefault 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.0as an explicit value rather than as missing.Documentation:
Tests:
Summary by CodeRabbit