Joomla 4 Menu Item
Params Error

01.09.2021
Eine Fehlermeldung auf rotem Grund mit einem schwarzen Joomla Logo im Vordergrund

The long-awaited major update Joomla 4 is slowly being used on more and more sites. However, converting self-developed templates is often not that easy.
Finally, the migration from Joomla 3 to version 4 has been completed without errors, but then you get a shock when you look at the front end. The Menu Item Params error is displayed:

Cannot access protected property Joomla\CMS\Menu\MenuItem::$params

This error is based on the changeover to the use of protected object values (params:protected). The problem has been known for some time, and there have been calls to make the old procedure update-proof:
https://issues.joomla.org/tracker/joomla-cms/30463.
However, it appears that this advice was not taken into account.

This means that they can no longer be accessed in the usual way. The old familiar version looks like this:

(int) $item->getParams()->get('aliasoptions');

Simply change your code locations as follows:

(int) $item->getParams()->get('aliasoptions');

This method for controlling protected values existed before, but did not have to be used in conjunction with the menu items. In addition, integer casting is used here so that the value can be processed without any problems and in a type-safe manner.
This should fix the problem and render the page as usual. If you have any further questions, please feel free to contact us.