No Code Attached Yet
avatar boddunan
boddunan
9 Feb 2021

Steps to reproduce the issue

  1. Add MenuRules to your component router. Make sure SEF URLs turned off.
    $this->attachRule(new JComponentRouterRulesMenu($this));

  2. Create menu item for your form page with the route something like this
    $link = 'index.php?option=com_communitysurveys&task=survey.add';

  3. Add controller which extends JControllerForm

  4. Call parent::add
    parent::add()

  5. The JControllerForm class redirect to the new page with the itemid corresponding to the form menu attached but with the following format.

/index.php?option=com_communitysurveys&view=form&layout=edit&**Itemid[0]=110**&return=aHR0cDovL2xvY2FsaG9zdC9qMy8

Since ItemId in the URL is an array, it throws errors on subsquent pages. like below.

Notice: Array to string conversion in D:\xampp\htdocs\j3\libraries\src\Helper\ModuleHelper.php on line 407

Expected result

The ItemId=110 was added and no errors on subsequent pages

Actual result

Itemid[0]=110 was added

System information (as much as possible)

Joomla 3.x

Additional comments

avatar boddunan boddunan - open - 9 Feb 2021
avatar joomla-cms-bot joomla-cms-bot - change - 9 Feb 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 9 Feb 2021
avatar ssnobben
ssnobben - comment - 13 Feb 2021

ping @Hackwar

avatar joomdonation
joomdonation - comment - 21 Feb 2021

Do we have a way to see this error in core components? Looking at this, I'm unsure if this is an issue with the router. Shouldn't the redirect URL is built in getRedirectToItemAppend method of the controller like how we do in Joomla core, like this https://github.com/joomla/joomla-cms/blob/4.0-dev/components/com_content/src/Controller/ArticleController.php#L284 ?

avatar boddunan
boddunan - comment - 22 Feb 2021

Note: This issue occur only when you have a menu item for the form page, with the URL in menu something like this - index.php?option=com_communitysurveys&view=form&layout=edit

Now, in my controller, getRedirectToItemAppend returns the value &layout=edit&Itemid=484&return=aHR0cDovL2xvY2FsaG9zdC9qMy8=

If I add var_dump in the FormController class just before the edit screen redirect set, the redirect value prints null. So the redirect value was not yet set.

Which is then passed to JRoute::_ in the FormController class

// Redirect to the edit screen.
$this->setRedirect(
	\JRoute::_(
		'index.php?option=' . $this->option . '&view=' . $this->view_item
		. $this->getRedirectToItemAppend(), false
	)
);

After this, if I print protected redirect value it shows like this

protected 'redirect' => string '/index.php?option=com_communitysurveys&view=form&layout=edit&Itemid[0]=2604&return=aHR0cDovL2xvY2FsaG9zdC9qMy8=

So definetely, this is not an issue with the getRedirectToItemAppend. JRoute is changing the ItemId to array when the menu item exists.

Following rules are added in the router file.

$this->attachRule(new JComponentRouterRulesMenu($this));
$this->attachRule(new JComponentRouterRulesStandard($this));
$this->attachRule(new JComponentRouterRulesNomenu($this));

Hope this helps.

avatar PhilETaylor
PhilETaylor - comment - 30 Apr 2021

Please confirm this is Joomla 3 ?

avatar boddunan
boddunan - comment - 1 May 2021

Yes, Joomla 3 latest version as on date.

avatar boddunan
boddunan - comment - 23 Sep 2021

Please note that I can reproduce this issue in Joomla 4 as well, precisely all Joomla3/4 versions using the new Joomla router.
P.S. If there is no menu item created, the issue won't occur.

avatar Hackwar
Hackwar - comment - 6 Dec 2022

I'm guessing you have defined the view configuration for your form view to take an ID. Remove that and the error should go away

avatar Hackwar Hackwar - change - 7 Dec 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-12-07 11:34:26
Closed_By Hackwar
Labels Added: No Code Attached Yet
Removed: ?
avatar Hackwar Hackwar - close - 7 Dec 2022
avatar Hackwar
Hackwar - comment - 7 Dec 2022

I looked up the code again and yes, that is indeed the problem. This is not a bug on Joomlas end. Closing this one.

Add a Comment

Login with GitHub to post a comment