0

I am working on a Magento2 extension. I added a column called "exported_to_stannp" to my customer grid using the following code:

app\code\Namespace\Module\Setup\InstallData.php

use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Model\Entity\Attribute\SetFactory;
use Magento\Eav\Model\Entity\Attribute\Source\Boolean;
use Magento\Eav\Model\Entity\Type;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface
{
    private $customerSetupFactory;
    private $attributeSetFactory;

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

    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();

        $customerSetup = $this->customerSetupFactory->create(['setup'=>$setup]);
        $customerSetup->removeAttribute(Customer::ENTITY, 'exported_to_stannp');

        $customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
        $attributeSetId = $customerEntity->getDefaultAttributeSetId();

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

        $entityTypeId = $customerSetup->getEntityTypeId(Customer::ENTITY);

        $customerSetup->addAttribute(
            Customer::ENTITY, 'exported_to_stannp', [
//                'type' => 'int',
                'backend' => \Magento\Customer\Model\Attribute\Backend\Data\Boolean::class,
                'frontend' => '',
                'label' => 'Exported to Stannp',
                'input' => 'select',
                'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
                'required' => false,
                'visible' => true,
                'user_defined' => true,
                'system' => false,
                'adminhtml_only' => true,
                'default' => 0,
                'global' => ScopedAttributeInterface::SCOPE_STORE,
                'value' => 0,
                'is_used_in_customer_segment' => true,
                "is_used_in_grid" => true,
                "is_visible_in_grid" => true,
                "is_filterable_in_grid" => true,
                "is_searchable_in_grid" => false
        ]
        );

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


        $installer->endSetup();
    }

}

app\code\Namespace\Module\view\adminhtml\ui_component\customer_listing.xml

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="customer_columns">
    <column name="exported_to_stannp">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Yesno</item>
            <item name="config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                <item name="filter" xsi:type="string">select</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="editor" xsi:type="string">select</item>
                <item name="dataType" xsi:type="string">select</item>
                <item name="label" xsi:type="string" translate="true">Exported to Stannp</item>
                <item name="source" xsi:type="string">customer</item>
                <item name="sortOrder" xsi:type="number">166</item>
            </item>
        </argument>
    </column>
</columns>
</listing>

app\code\Namespace\Module\etc\indexer.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Indexer/etc/indexer.xsd">
    <indexer id="customer_grid">
        <fieldset name="customer" source="Magento\Customer\Model\ResourceModel\Customer\Collection" provider="Magento\Customer\Model\Indexer\AttributeProvider">
            <field name="exported_to_stannp" xsi:type="filterable" dataType="int"/>
        </fieldset>
    </indexer>
</config>

Everything works fine, except for the export functionality in grid. I get the following error:

 Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Framework\View\Element\UiComponentFactory::argumentsResolver() must be of the type array, null given, called in /Users/iunia/Sites/magento2/vendor/magento/framework/View/Element/UiComponentFactory.php on line 213 and defined in /Users/iunia/Sites/magento2/vendor/magento/framework/View/Element/UiComponentFactory.php on line 164

I put logs in 2 files: vendor/magento/framework/View/Element/UiComponentFactory.php line 212 $rawComponentData and vendor/magento/module-ui/Component/Listing/Columns/Column.php line 73 $this->getName() and $dataType.

/Users/iunia/Sites/magento2/vendor/magento/module-ui/Component/Listing/Columns/Column.php:73:string 'exported_to_stannp' (length=18)
/Users/iunia/Sites/magento2/vendor/magento/module-ui/Component/Listing/Columns/Column.php:74:string 'select' (length=6) /Users/iunia/Sites/magento2/vendor/magento/framework/View/Element/UiComponentFactory.php:212:
array (size=4)
  'arguments' => 
    array (size=1)
      'data' => 
        array (size=1)
          'config' => 
            array (size=2)
              ...
  'attributes' => 
    array (size=3)
      'class' => string 'Magento\Ui\Component\Form\Element\Select' (length=40)
      'component' => string 'Magento_Ui/js/form/element/select' (length=33)
      'template' => string 'ui/form/field' (length=13)
  'children' => 
    array (size=0)
      empty
  'uiComponentType' => string 'select' (length=6)

/Users/iunia/Sites/magento2/vendor/magento/module-ui/Component/Listing/Columns/Column.php:73:string 'exported_to_stannp' (length=18)
/Users/iunia/Sites/magento2/vendor/magento/module-ui/Component/Listing/Columns/Column.php:74:string 'varchar' (length=7)
/Users/iunia/Sites/magento2/vendor/magento/framework/View/Element/UiComponentFactory.php:212:null

If I add the ($this->getName() != 'exported_to_stannp') to the condition at line 74, it works as expected.

$dataType is null the second time in the logs, and only for any export.

Please help.

0

Commenting out/removing the following code fixed my problem. I still have to test it on a fresh install, but for now it seems to be working.

app\code\Namespace\Module\view\adminhtml\ui_component\customer_listing.xml

<columns name="customer_columns">
    <column name="exported_to_stannp">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Yesno</item>
            <item name="config" xsi:type="array">
                <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                <item name="filter" xsi:type="string">select</item>
                <item name="visible" xsi:type="boolean">true</item>
                <item name="editor" xsi:type="string">select</item>
                <item name="dataType" xsi:type="string">select</item>
                <item name="label" xsi:type="string" translate="true">Exported to Stannp</item>
                <item name="source" xsi:type="string">customer</item>
                <item name="sortOrder" xsi:type="number">166</item>
            </item>
        </argument>
    </column>
</columns>
  • Yes, but this removes your custom column as well. – Mladen Ilić Jun 12 '18 at 10:36
  • It didn't, for me. It works perfectly. – Iunia Jun 27 '18 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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