gantry / gantry5

:rocket: Next Generation Template / Theme Framework
http://gantry.org
1.03k stars 203 forks source link

Administrator Menu Editor Unusable in Gantry 5.5.15 with PHP 8.1.13 #3103

Open bascherz opened 1 year ago

bascherz commented 1 year ago

This issue was previously mentioned in https://github.com/gantry/gantry5/issues/3073. I was asked to enter a new issue focusing specifically on this problem.

As of updating to 5.5.15, which resolved this problem (https://github.com/gantry/gantry5/issues/3088), the Menu Editor is no longer usable. This is what I get on all my sites running 5.5.15 (both Hydrogen and Helium templates) for all menus. This has been occurring with Joomla! 4.2.5 and 4.2.6 since updating to PHP 8.1.13 and Gantry 5.5.15.

image

iantrudell commented 1 year ago

Same issue here, says invalid menu structure

N8Solutions commented 1 year ago

@bascherz what version of PHP are you using when this error happens?

iantrudell commented 1 year ago

@bascherz what version of PHP are you using when this error happens?

PHP 8.1.12

bascherz commented 1 year ago

@iantrudell You know, I didn't think about it when I posted, since earlier I had posted that I needed to update to Gantry 5.5.15 to fix a front end fatal error issue (#3088) with PHP 8.1. So it's quite likely it's got something to do with that. I had been running PHP 7.3 and got tired of J!4 complaining about it. Gantry 5.5.15 did resolve that problem, so I am now on PHP 8.1.13. It is since then that I noticed this issue.

By the way, I tried backing up to PHP 8.0 yesterday and got a different front end fatal error with Gantry.

iantrudell commented 1 year ago

I dug a little deeper into this and I have a few fixes:

In libraries\gantry5\src\classes\Gantry\Admin\Controller\Html\Menu.php On line 573, replace this:

$items = json_decode($items, true);

with this:

$items = json_decode((string)$items, true);

In libraries\gantry5\vendor\twig\twig\src\Extension\CoreExtension.php On line 521, replace this:

return strtr($str, $from, $to);

with this:

return strtr((string)$str, $from, $to);

On line 528, replace this:

return strtr($str, twig_to_array($from));

with this:

return strtr((string)$str, twig_to_array($from));

On line 996, replace this:

return trim($string, $characterMask);

with this:

return trim((string)$string, $characterMask);

On line 998, replace this:

return ltrim($string, $characterMask);

with this:

return ltrim((string)$string, $characterMask);

On line 1000, replace this:

return rtrim($string, $characterMask);

with this:

return rtrim((string)$string, $characterMask);

In libraries\gantry5\compat\vendor\twig\twig\src\Extension\CoreExtension.php On line 527, replace this:

return strtr($str, $from, $to);

with this:

return strtr((string)$str, $from, $to);

On line 534, replace this:

return strtr($str, twig_to_array($from));

with this:

return strtr((string)$str, twig_to_array($from));

On line 990, replace this:

return trim($string, $characterMask);

with this:

return trim((string)$string, $characterMask);

On line 992, replace this:

return ltrim($string, $characterMask);

with this:

return ltrim((string)$string, $characterMask);

On line 994, replace this:

return rtrim($string, $characterMask);

with this:

return rtrim((string)$string, $characterMask);

This forces null string variables to be empty strings (since you are no longer allowed to pass in null to strtr in PHP 8.1).

This should also make the Menu Editor usable again (you may have to add the #[\ReturnTypeWillChange] annotations to various Pimple and Twig files too to get the warnings to disappear).

bascherz commented 1 year ago

@iantrudell, those changes do seem to fix the issue. Any idea how long it might be for an official fix to appear?

Thanks, bud!

joseOlivares commented 1 year ago

I have the same issue.

N8Solutions commented 1 year ago

I have the same issue.

@joseOlivares You should download the latest release 5.5.16.

You can find the latest releases here: https://github.com/gantry/gantry5/releases