experius / Magento-2-Module-Experius-WysiwygDownloads

Available At Packagist
https://packagist.org/search/?q=experius
Open Software License 3.0
101 stars 27 forks source link

PHP deprication error after upgrade to PHP 8.1 #24

Closed hannes011 closed 1 year ago

hannes011 commented 1 year ago

Hi everyone,

After upgrading to PHP 8 there is an error occurring for the image pagebuilder element if you choose "select from gallery".

The error appears by not displaying any of the gallery content (only the directory tree). Furthermore, you'll find the following log in your system.log: Exception: Deprecated Functionality: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in vendor/experius/module-wysiwygdownloads/Helper/Settings.php on line 86 in /var/www/html/magento/vendor/magento/framework/App/ErrorHandler.php:62

Prerequisite is that you've NOT added any additional file types to: Config > General > Content Management > WYSIWYG Options > Extra Allowed Filetypes in the WYSIWYG-editor

Quick workaround would be also to just add any type to that configuration.

I'm on Magento 2.4.5

hannes011 commented 1 year ago

Solution to fix this issue I've created the following patch:

diff --git a/Helper/Settings.php b/Helper/Settings.php
index 03c9641..8868b64 100644
--- a/Helper/Settings.php
+++ b/Helper/Settings.php
@@ -83,7 +83,7 @@ class Settings extends \Magento\Framework\App\Helper\AbstractHelper
    public function getExtraFiletypes()
    {
       $filetypes = array();
-      $settings = json_decode($this->getConfigValue(self::CONFIG_PATH_FILETYPES));
+      $settings = json_decode($this->getConfigValue(self::CONFIG_PATH_FILETYPES) ?? '[]');
       if ($settings) {
           foreach($settings as $setting){
               $filetypes[] =  $setting->extension;
jornwildenbeest commented 1 year ago

@hannes011 ran in to the same thing.

Quick fix is also to just add an empty array in the settings:

image

EDIT: sorry, jus saw that you added the samething in the description of the issue