I have some issues saving categories in Magento 2.3.5, when I click save after changing the SEO information (Meta Title, Meta description and Meta Keywords) gives me this error.
Argument 1 passed to Magento\Catalog\Model\Category\FileInfo::removeStorePath() must be of the type string, array given, called in /home/adminpsol2016/public_html/vendor/magento/module-catalog/Model/Category/FileInfo.php on line 167
here you can see a screenshot of the problem.
This gave me quite a headache but finally managed to get to the bottom of it; my case is as follow:
Repro:
backend_model
:=Magento\Catalog\Model\Category\Attribute\Backend\Image
Reason:
If you look at https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php#L240 you'll see that this has the effect of storing the entire POST data of the current form request to session (also the
LocalizedException
block does the same). Later on, this data is restored in https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php#L95 and immediately after the form information for theimage
attribute is stripped/cleared. This of course does not handle any custom attribute of Image type we might have defined for our category entity.Solution:
I added an
after*
plugin (inadminhtml
area only) on\Magento\Framework\Session\SessionManager::__call
, where I explicitly check that the invoked method isgetCategoryData
: if this is the case, I fetch all the custom category image attributes, and strip them from the returned array likeCategory/Edit
does.This way any further exception message is correctly displayed in the backoffice (granted it extends
LocalizedException
)