No Code Attached Yet bug
avatar bcraigie
bcraigie
30 May 2024

Steps to reproduce the issue

Create a menu item that points to something belonging to a component. For example a form in Chronoforms.

Remove that component (perhaps you've installed a newer version of it)

You can see that the menu page shows you "component not found". Try to edit the menu item.

Expected result

Be able to edit the menu item to be able to point it elsewhere (for example a newer version of the component)

Actual result

Stack trace is produced as follows:

Function Location

1 () JROOT/libraries/vendor/joomla/filesystem/src/Path.php:194
2 Joomla\Filesystem\Path::clean() JROOT/administrator/components/com_menus/src/Model/ItemModel.php:1131
3 Joomla\Component\Menus\Administrator\Model\ItemModel->preprocessForm() JROOT/libraries/src/MVC/Model/FormBehaviorTrait.php:115
4 Joomla\CMS\MVC\Model\FormModel->loadForm() JROOT/administrator/components/com_menus/src/Model/ItemModel.php:517
5 Joomla\Component\Menus\Administrator\Model\ItemModel->getForm() JROOT/libraries/src/MVC/View/AbstractView.php:159
6 Joomla\CMS\MVC\View\AbstractView->get() JROOT/administrator/components/com_menus/src/View/Item/HtmlView.php:88
7 Joomla\Component\Menus\Administrator\View\Item\HtmlView->display() JROOT/libraries/src/MVC/Controller/BaseController.php:697
8 Joomla\CMS\MVC\Controller\BaseController->display() JROOT/administrator/components/com_menus/src/Controller/DisplayController.php:74
9 Joomla\Component\Menus\Administrator\Controller\DisplayController->display() JROOT/libraries/src/MVC/Controller/BaseController.php:730
10 Joomla\CMS\MVC\Controller\BaseController->execute() JROOT/libraries/src/Dispatcher/ComponentDispatcher.php:143
11 Joomla\CMS\Dispatcher\ComponentDispatcher->dispatch() JROOT/libraries/src/Component/ComponentHelper.php:361
12 Joomla\CMS\Component\ComponentHelper::renderComponent() JROOT/libraries/src/Application/AdministratorApplication.php:150
13 Joomla\CMS\Application\AdministratorApplication->dispatch() JROOT/libraries/src/Application/AdministratorApplication.php:195
14 Joomla\CMS\Application\AdministratorApplication->doExecute() JROOT/libraries/src/Application/CMSApplication.php:306
15 Joomla\CMS\Application\CMSApplication->execute() JROOT/administrator/includes/app.php:58
16 require_once() JROOT/administrator/index.php:32

System information (as much as possible)

Joomla! Version Joomla! 5.1.0 Stable [ Kudumisha ] 16-April-2024 16:00 GMT

Additional comments

In the file JROOT/libraries/vendor/joomla/filesystem/src/Path.php

In this scenario the $path is a boolean, not a string (because the component doesn't exist)

At this statement:

public static function clean($path, $ds = \DIRECTORY_SEPARATOR)
{
if (!\is_string($path)) {
throw new \InvalidArgumentException('You must specify a non-empty path to clean');
}

Before the if statement, you could check if $path is (presumably) False, and if so, just return. There is no need to crash out. This enables the editing of the menu item to proceed without the user having to resort to editing the Path.php file to fix it, or having to delete their menu item and re-create it. A stack trace is never desirable when a simple fix can be made.

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
3.00

avatar bcraigie bcraigie - open - 30 May 2024
avatar bcraigie bcraigie - change - 30 May 2024
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 30 May 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 30 May 2024
avatar brianteeman
brianteeman - comment - 30 May 2024

A stack trace is never desirable when a simple fix can be made.

You only get the stack trace if you have debug enabled. In normal use you get

image

But if you have a fix that is more helpful please submit a pull request with that code

avatar bcraigie
bcraigie - comment - 30 May 2024

Hi Brian. Ah yes! I do have debug on and you are correct. It would still be preferable to enable the user to edit the menu item than to receive the error.

I've never submitted a pull request before, and I don't know if the fix I would suggest is acceptable, however it works for me (tested) by simply replacing the "throw new..." line I quoted above with "return;"

The thing I don't know is if there are ever any circumstances where one would desire the error message instead of silently ignoring the problem because I don't have enough in-depth knowledge of the code that may call it under other circumstances. It certainly fixes this specific scenario.

I shall see if I can submit the pull request. :-)


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43580.
avatar chmst chmst - change - 31 May 2024
Labels Added: bug
avatar chmst chmst - labeled - 31 May 2024
avatar rdeutz
rdeutz - comment - 1 Jun 2024

I think your fix is at the wrong place and would have to many side effects. Then main problem here is that the application can't load the form definition for the menu item. This is something you can't fix in a proper way. I think in such situations deleting the menu item and creating a new one would be the way to go.

avatar OctavianC
OctavianC - comment - 3 Jun 2024

Please test #43604 as this should solve the issue at the com_menus level instead of globally on the Path class.

avatar alikon alikon - change - 3 Jun 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-06-03 06:34:53
Closed_By alikon
avatar alikon alikon - close - 3 Jun 2024
avatar alikon
alikon - comment - 3 Jun 2024

closing as we have a pr #43604

Add a Comment

Login with GitHub to post a comment