I've added a custom image attribute to my category with Magento 2 Module Generator from https://mage2gen.com/ (Magento version 2.2) Everything is perfect, but when I upload an image to the attribute and save category, an error occurred:

Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Cannot use string offset as an array in C:\xampp\htdocs\magento2\vendor\magento\module-ui\Component\Wrapper\UiComponent.php on line 0

This is my InstallData.php

namespace Vendor\Module\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;

class InstallData implements InstallDataInterface
    private $eavSetupFactory;
    public function __construct(EavSetupFactory $eavSetupFactory)
        $this->eavSetupFactory = $eavSetupFactory;

    public function install(
        ModuleDataSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

                'type' => 'varchar',
                'label' => 'Thumbnail Image',
                'input' => 'image',
                'sort_order' => 5,
                'source' => '',
                'global' => 0,
                'visible' => true,
                'required' => false,
                'user_defined' => false,
                'default' => '',
                'group' => 'General Information',
                'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image'


And the category_form.xml

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general">
    <field name="thumbnail_image">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="required" xsi:type="boolean">false</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>
                <item name="sortOrder" xsi:type="number">5</item>
                <item name="dataType" xsi:type="string">string</item>
                <item name="formElement" xsi:type="string">fileUploader</item>
                <item name="label" translate="true" xsi:type="string">Thumbnail Image</item>
                <item name="uploaderConfig" xsi:type="array">
                    <item name="url" path="catalog/category_image/upload" xsi:type="url"/>
                <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item>
                <item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item>
                <item name="source" xsi:type="string">category</item>

I am sure the value is saved OK (checked in database for eav_attribute, catalog_category_entity_varchar tables) and the image is uploaded into \pub\media\catalog\category

Thanks for any help!

1 Answer 1


You can try this fix

it's helped me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.