Skip to content

magento 2 newsletter subscription block custom column with options

on magento 2 we can add additional columns to the subscribers grid by using the newsletter_subscription_block layout xml file. The original file in the MagentoNewsletter module has the column for type guest/customer set as this:

<block class="MagentoBackendBlockWidgetGridColumn" name="adminhtml.newslettrer.subscriber.grid.columnSet.type" as="type">
    <arguments>
        <argument name="header" xsi:type="string" translate="true">Type</argument>
        <argument name="index" xsi:type="string">type</argument>
        <argument name="type" xsi:type="string">options</argument>
        <argument name="options" xsi:type="array">
            <item name="guest" xsi:type="array">
                <item name="value" xsi:type="string">1</item>
                <item name="label" xsi:type="string" translate="true">Guest</item>
            </item>
            <item name="customer" xsi:type="array">
                <item name="value" xsi:type="string">2</item>
                <item name="label" xsi:type="string" translate="true">Customer</item>
            </item>
        </argument>
    </arguments>
</block>               

But the column “type” is not present in the database table, so how is this column generated?

I tried to test this code with a custom column that I had previously added to the newsletter subscribers table:

<block class="MagentoBackendBlockWidgetGridColumn" name="adminhtml.newslettrer.subscriber.grid.columnSet.type" as="mycolumn">
    <arguments>
        <argument name="header" xsi:type="string" translate="true">My Column</argument>
        <argument name="index" xsi:type="string">mycolumn</argument>
        <argument name="mycolumn" xsi:type="string">options</argument>
        <argument name="options" xsi:type="array">
            <item name="guest" xsi:type="array">
                <item name="value" xsi:type="string">1</item>
                <item name="label" xsi:type="string" translate="true">Guest</item>
            </item>
            <item name="customer" xsi:type="array">
                <item name="value" xsi:type="string">2</item>
                <item name="label" xsi:type="string" translate="true">Customer</item>
            </item>
        </argument>
    </arguments>
</block>               

But this code does not work. I can see my column, but it displays the original values as they are saved in the database (1 or 2), not the labels.

I also thought the original module was using the UIComponent Providers to edit the information displayed in the column but there is no Ui folder in the module-newsletter folder.

How can we re-create the same logic as the “type” column with our own custom columns?