2

I am making customer file attribute,first time i am getting that error -

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/html/xxx/xxx/vendor/magento/framework/File/Uploader.php on line 552

After solve this then i am getting that error in console -

Uncaught ReferenceError: Base64 is not defined

i am using this code -

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Customer\Model\Customer;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;


class UpgradeData implements UpgradeDataInterface {

    protected $customerSetupFactory;
    private $attributeSetFactory;

    public function __construct(
    CustomerSetupFactory $customerSetupFactory, AttributeSetFactory $attributeSetFactory
    ) {
        $this->customerSetupFactory = $customerSetupFactory;
        $this->attributeSetFactory = $attributeSetFactory;
    }


    public function upgrade( ModuleDataSetupInterface $setup, ModuleContextInterface $context ) {

        if (version_compare($context->getVersion(), '1.0.4') < 0) {

            $setup->startSetup();
            $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

            $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
            $attributeSetId = $customerEntity->getDefaultAttributeSetId();

            $attributeSet = $this->attributeSetFactory->create();
            $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

            $customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'twilio_image', [
                'type' => 'text',
                'label' => 'Twilio Image',
                'input' => 'file',
                "source" => '',
                'required' => false,
                'default' => '0',
                'visible' => true,
                'user_defined' => true,
                'sort_order' => 210,
                'position' => 210,
                'system' => false,
            ]);

            $image = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'twilio_image')
                    ->addData([
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => ['adminhtml_customer', 'customer_account_create', 'customer_account_edit'],
            ]);

            $image->save();
            $setup->endSetup();
        }  
    }
}

/vendor/magento/module-theme/view/adminhtml/ui_component/design_config_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">design_config_form.design_config_form_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true">Theme Information</item>
        <item name="template" xsi:type="string">templates/form/collapsible</item>
    </argument>
    <settings>
        <buttons>
            <button name="save_and_continue" class="Magento\Theme\Block\Adminhtml\Design\Config\Edit\SaveAndContinueButton"/>
            <button name="save" class="Magento\Theme\Block\Adminhtml\Design\Config\Edit\SaveButton"/>
            <button name="back" class="Magento\Theme\Block\Adminhtml\Design\Config\Edit\BackButton"/>
        </buttons>
        <namespace>design_config_form</namespace>
        <dataScope>data</dataScope>
        <deps>
            <dep>design_config_form.design_config_form_data_source</dep>
        </deps>
    </settings>
    <dataSource name="design_config_form_data_source">
        <argument name="data" xsi:type="array">
            <item name="js_config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
            </item>
        </argument>
        <settings>
            <submitUrl path="theme/design_config/save"/>
        </settings>
        <dataProvider class="Magento\Theme\Model\Design\Config\DataProvider" name="design_config_form_data_source">
            <settings>
                <clientConfig>
                    <param name="validateBeforeSave" xsi:type="boolean">false</param>
                </clientConfig>
                <requestFieldName>scope</requestFieldName>
                <primaryFieldName>scope</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>
    <fieldset name="other_settings" sortOrder="30">
        <settings>
            <label translate="true">Other Settings</label>
        </settings>
        <fieldset name="head">
            <settings>
                <level>1</level>
                <collapsible>true</collapsible>
                <label translate="true">HTML Head</label>
            </settings>
            <field name="head_shortcut_icon" formElement="imageUploader">
                <settings>
                    <notice translate="true">Not all browsers support all these formats!</notice>
                    <label translate="true">Favicon Icon</label>
                    <componentType>imageUploader</componentType>
                </settings>
                <formElements>
                    <imageUploader>
                        <settings>
                            <allowedExtensions>jpg jpeg gif png ico apng</allowedExtensions>
                            <maxFileSize>2097152</maxFileSize>
                            <uploaderConfig>
                                <param xsi:type="string" name="url">theme/design_config_fileUploader/save</param>
                            </uploaderConfig>
                        </settings>
                    </imageUploader>
                </formElements>
            </field>
            <field name="head_default_title" formElement="input">
                <settings>
                    <validation>
                        <rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>text</dataType>
                    <label translate="true">Default Page Title</label>
                    <dataScope>head_default_title</dataScope>
                </settings>
            </field>
            <field name="head_title_prefix" formElement="input">
                <settings>
                    <validation>
                        <rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>text</dataType>
                    <label translate="true">Page Title Prefix</label>
                    <dataScope>head_title_prefix</dataScope>
                </settings>
            </field>
            <field name="head_title_suffix" formElement="input">
                <settings>
                    <validation>
                        <rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>text</dataType>
                    <label translate="true">Page Title Suffix</label>
                    <dataScope>head_title_suffix</dataScope>
                </settings>
            </field>
            <field name="head_default_description" formElement="textarea">
                <settings>
                    <validation>
                        <rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>text</dataType>
                    <label translate="true">Default Meta Description</label>
                    <dataScope>head_default_description</dataScope>
                </settings>
            </field>
            <field name="head_default_keywords" formElement="textarea">
                <settings>
                    <validation>
                        <rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>text</dataType>
                    <label translate="true">Default Meta Keywords</label>
                    <dataScope>head_default_keywords</dataScope>
                </settings>
            </field>
            <field name="head_includes" formElement="textarea">
                <settings>
                    <notice translate="true">This will be included before head closing tag in page HTML.</notice>
                    <dataType>text</dataType>
                    <label translate="true">Scripts and Style Sheets</label>
                    <dataScope>head_includes</dataScope>
                </settings>
            </field>
            <field name="head_demonotice" formElement="select">
                <settings>
                    <dataType>text</dataType>
                    <label translate="true">Display Demo Store Notice</label>
                    <dataScope>head_demonotice</dataScope>
                </settings>
                <formElements>
                    <select>
                        <settings>
                            <options class="Magento\Config\Model\Config\Source\Yesno"/>
                        </settings>
                    </select>
                </formElements>
            </field>
        </fieldset>
        <fieldset name="header">
            <settings>
                <level>1</level>
                <collapsible>true</collapsible>
                <label translate="true">Header</label>
            </settings>
            <field name="header_logo_src" formElement="imageUploader">
                <settings>
                    <label translate="true">Logo Image</label>
                    <componentType>imageUploader</componentType>
                </settings>
                <formElements>
                    <imageUploader>
                        <settings>
                            <allowedExtensions>jpg jpeg gif png</allowedExtensions>
                            <maxFileSize>2097152</maxFileSize>
                            <uploaderConfig>
                                <param xsi:type="string" name="url">theme/design_config_fileUploader/save</param>
                            </uploaderConfig>
                        </settings>
                    </imageUploader>
                </formElements>
            </field>
            <field name="header_logo_width" formElement="input">
                <settings>
                    <validation>
                        <rule name="validate-digits" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>number</dataType>
                    <label translate="true">Logo Attribute Width</label>
                    <dataScope>header_logo_width</dataScope>
                </settings>
            </field>
            <field name="header_logo_height" formElement="input">
                <settings>
                    <validation>
                        <rule name="validate-digits" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>number</dataType>
                    <label translate="true">Logo Attribute Height</label>
                    <dataScope>header_logo_height</dataScope>
                </settings>
            </field>
            <field name="header_welcome" formElement="input">
                <settings>
                    <validation>
                        <rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>text</dataType>
                    <label translate="true">Welcome Text</label>
                    <dataScope>header_welcome</dataScope>
                </settings>
            </field>
            <field name="header_logo_alt" formElement="input">
                <settings>
                    <validation>
                        <rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>text</dataType>
                    <label translate="true">Logo Image Alt</label>
                    <dataScope>header_logo_alt</dataScope>
                </settings>
            </field>
        </fieldset>
        <fieldset name="footer">
            <settings>
                <level>1</level>
                <collapsible>true</collapsible>
                <label translate="true">Footer</label>
            </settings>
            <field name="footer_absolute_footer" formElement="textarea">
                <settings>
                    <notice translate="true">This will be displayed just before the body closing tag.</notice>
                    <dataType>text</dataType>
                    <label translate="true">Miscellaneous HTML</label>
                    <dataScope>footer_absolute_footer</dataScope>
                </settings>
            </field>
            <field name="footer_copyright" formElement="textarea">
                <settings>
                    <validation>
                        <rule name="validate-no-html-tags" xsi:type="boolean">true</rule>
                    </validation>
                    <dataType>text</dataType>
                    <label translate="true">Copyright</label>
                    <dataScope>footer_copyright</dataScope>
                </settings>
            </field>
        </fieldset>
        <fieldset name="search_engine_robots" sortOrder="120">
            <settings>
                <level>1</level>
                <collapsible>true</collapsible>
                <label>Search Engine Robots</label>
            </settings>
            <field name="default_robots" formElement="select">
                <settings>
                    <notice translate="true">This will be included before head closing tag in page HTML.</notice>
                    <dataType>text</dataType>
                    <label translate="true">Default Robots</label>
                    <dataScope>default_robots</dataScope>
                    <scopeLabel>[WEBSITE]</scopeLabel>
                </settings>
                <formElements>
                    <select>
                        <settings>
                            <options class="Magento\Config\Model\Config\Source\Design\Robots"/>
                        </settings>
                    </select>
                </formElements>
            </field>
            <field name="custom_instructions" formElement="textarea">
                <settings>
                    <dataType>text</dataType>
                    <label translate="true">Edit custom instruction of robots.txt File</label>
                    <dataScope>custom_instructions</dataScope>
                    <scopeLabel>[WEBSITE]</scopeLabel>
                </settings>
            </field>
            <field name="reset_to_defaults" class="Magento\Theme\Ui\Component\Design\Config\SearchRobots\ResetButton" component="Magento_Theme/js/form/component/robots-reset-button" template="Magento_Theme/form/button-field" formElement="button">
                <settings>
                    <notice translate="true">This action will delete your custom instructions and reset robots.txt file to system's default settings.</notice>
                    <dataScope>reset_to_defaults</dataScope>
                    <scopeLabel>[WEBSITE]</scopeLabel>
                </settings>
                <formElements>
                    <button>
                        <settings>
                            <title translate="true">Reset To Defaults</title>
                        </settings>
                    </button>
                </formElements>
            </field>
        </fieldset>
    </fieldset>
</form>
2
  • error is from Js not from php
    – fmsthird
    May 22, 2019 at 10:04
  • here both are related May 22, 2019 at 10:05

3 Answers 3

1

if you are using magento2.3 you have to just change

type="fileUploader"

to

type="imageUploader"

in your ui compoent grid

this error is not regarding attribute creation ,it's mistake in custom ui component grid

6
  • yes i am using magento2.3,i already change fileUploader to imageUploader but not working May 22, 2019 at 10:17
  • Have you check after flushing cache? May 22, 2019 at 10:17
  • please paste vendor/magento/module-theme/view/adminhtml/ui_component/design_config_form.xml in question May 22, 2019 at 10:19
  • please check now i updated May 22, 2019 at 10:21
  • Please also make sure that you have not used fileUploader type in custom grid @sumeetbajaj May 22, 2019 at 10:25
1

One of the possible solution of this issue by overriding the

vendor/magento/module-theme/view/adminhtml/ui_component/design_config_form.xml

Change the formElement from fileUploader to imageUploader

I hope this will help

1
  • 1
    i already add there but not not working May 22, 2019 at 10:16
1

Check the following files:

/vendor/magento/module-email/view/adminhtml/ui_component/design_config_form.xml /vendor/magento/module-catalog/view/adminhtml/ui_component/design_config_form.xml /vendor/magento/module-backend/view/adminhtml/ui_component/design_config_form.xml /vendor/magento/module-swatches/view/adminhtml/ui_component/design_config_form.xml /vendor/magento/module-theme/view/adminhtml/ui_component/design_config_form.xml

Then search for

formElement="fileUploader"

replace with

formElement="imageUploader" 

in all the files

Clear cache, then check if the issue is resolved.

4
  • i already changed on that files but here - /vendor/magento/module-backend/view/adminhtml/ui_component/design_config_form.xml is not present fileUploader May 22, 2019 at 10:35
  • it is not working,tried to run all commands May 22, 2019 at 10:35
  • did you run setup:di:compile as well?
    – fmsthird
    May 22, 2019 at 10:36
  • yes i run di:compile still not working May 22, 2019 at 10:42

Your Answer

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

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