1

I have created a new module which provides a Magento 2 widget. The widget was previously working but now when I go Content -> Widgets in Magento admin I get the following error:

PHP Fatal error:  Uncaught Error: Call to a member function getNamedItem() on null in /var/www/src/vendor/magento/module-widget/Model/Config/Converter.php:51

Its related to thewidget.xml file as if I remove it the error doesn't occur. My widget.xml looks like this:

<widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
    <widget id="category_list" class="Mynamespace\CatalogWidget\Block\Category\CategoryList" is_email_compatible="true"
            placeholder_image="Magento_CatalogWidget::images/products_list.png" ttl="86400">
        <label translate="true">Catalog Category List</label>
        <description translate="true">List of Categories</description>
        <parameters>
            <parameter name="title" xsi:type="text" required="false" visible="true">
                <label translate="true">Title</label>
            </parameter>
            <parameter name="template" xsi:type="select" required="true" visible="true">
                <label translate="true">Template</label>
                <options>
                    <option name="default" value="category/widget/content/grid.phtml" selected="true">
                        <label translate="true">Category Grid Template</label>
                    </option>
                </options>
            </parameter>
            <parameter name="products_count" xsi:type="text" required="true" visible="true">
                <label translate="true">Number of Categories to Display</label>
                <value>10</value>
            </parameter>
            <parameter name="cache_lifetime" xsi:type="text" visible="true">
                <label translate="true">Cache Lifetime (Seconds)</label>
                <description translate="true">86400 by default, if not set. To refresh instantly, clear the Blocks HTML Output cache.</description>
            </parameter>
        </parameters>
    </widget>
</widgets>
1

I figured this one out. Turns out it was due to a comment in the parameters of my widget.xml that was causing this. The Magento\Widget\Model\Config\Converter::convert method reads this comment and tries to treat it like a parameter. e.g:

<parameters>
            <parameter name="title" xsi:type="text" required="false" visible="true">
                <label translate="true">Title</label>
            </parameter>
</parameters>

works, but:

<parameters>
            <!-- My title parameter -->
            <parameter name="title" xsi:type="text" required="false" visible="true">
                <label translate="true">Title</label>
            </parameter>
</parameters>

does not.

Update: Turns out this is a known issue

  • Wow. Super lame! I had this today when I commented a parameter out. :-/ – Giel Berkers Aug 22 '17 at 14:19

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.