No Code Attached Yet bug

Steps to reproduce the issue

  1. Create two menus, e.g. "menu 1" and "menu 2". Mine are for 2 languages. Not sure if language matters.
  2. Create a menu item in menu 1. Click Save.
  3. Edit the first menu item. Change the title and set the menu to the menu 2. I also changed the language. Select "Save as Copy".

Expected result

The first menu item should remain in menu 1 and the copy should be found in menu 2.

Actual result

Both the first and its copy end up in menu 2.

System information (as much as possible)

Joomla 4.1.0

Additional comments

avatar ConfidantCommunications ConfidantCommunications - open - 25 Mar 2022
avatar joomla-cms-bot joomla-cms-bot - change - 25 Mar 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 25 Mar 2022
avatar simbus82
simbus82 - comment - 25 Mar 2022

Confirmed! Same problem in 4.1.1-rc1
It's a bug.

avatar brianteeman
brianteeman - comment - 25 Mar 2022

confirmed

avatar anmode
anmode - comment - 28 Mar 2022

Yes, I am also able to reproduce it. can anyone guide me on what to do to solve this issue?

avatar ReLater
ReLater - comment - 28 Mar 2022

I think the error happens here: https://github.com/joomla/joomla-cms/blob/4.1-dev/administrator/components/com_menus/src/Model/ItemModel.php#L1429

$pk is detected wrongly:
$pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('item.id');

Background:

  • The controller sets $data['id'] explicitly to 0 if we're in a save2copy task.
  • Therefore $data['id'] is detected as empty in the model and $pk falls back to $this->getState('item.id') which is the id of the menu item to be copied.

Maybe solution:
$pk = (!empty($data['id']) || $data['id'] === 0) ? $data['id'] : (int) $this->getState('item.id');

avatar ReLater
ReLater - comment - 28 Mar 2022

Maybe solution:

Not tested enough, but it seems to fix the issue for me.

avatar ReLater
ReLater - comment - 28 Mar 2022

@anmode
If you want: Do you like to provide a pr with my solution (or a better one if you think so)?

avatar anmode
anmode - comment - 28 Mar 2022

@ReLater I'll test your solution. If it works fine than awesome. I would like to send pr with your solution and i I'll also try to add something.

avatar chmst chmst - change - 28 Mar 2022
Labels Added: bug
avatar chmst chmst - labeled - 28 Mar 2022
avatar anmode
anmode - comment - 28 Mar 2022

yeah! Fantastic this working correctly. I have tested it. could i generate a pr for it?

avatar ReLater
ReLater - comment - 28 Mar 2022

could i generate a pr for it?

Everybody is allowed to provide a pr for Joomla without asking before. You, too ;-)
It will be reviewed and tested then by others. You can make changes if needed.

avatar anmode
anmode - comment - 28 Mar 2022

could i generate a pr for it?

Everybody is allowed to provide a pr for Joomla without asking before. You, too ;-) It will be reviewed and tested then by others. You can make changes if needed.

okay sure! Thanks for the solution btw :).

avatar drmenzelit drmenzelit - change - 29 Mar 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-03-29 05:50:07
Closed_By drmenzelit
avatar drmenzelit drmenzelit - close - 29 Mar 2022
avatar drmenzelit
drmenzelit - comment - 29 Mar 2022

Closing as we have a PR #37395

Add a Comment

Login with GitHub to post a comment