2

I'm using Magento 2.1.8 fresh install. I'm trying to get my mega-menu options in the category section. Now i get this error when going to the category page :

> 1 exception(s): Exception #0
> (Magento\Framework\Exception\LocalizedException): The configuration
> parameter "componentType" is a required for "mega-menu" component.
> 
> Exception #0 (Magento\Framework\Exception\LocalizedException): The
> configuration parameter "componentType" is a required for "mega-menu"
> component.
> #0 /data/sites/web/demoehaleeu/www/vendor/magento/framework/View/Element/UiComponentFactory.php(361):
> Magento\Framework\View\Element\UiComponentFactory->mergeMetadataItem(Array,
> Array, true)
> #1 /data/sites/web/demoehaleeu/www/vendor/magento/framework/View/Element/UiComponentFactory.php(272):
> Magento\Framework\View\Element\UiComponentFactory->mergeMetadataItem(Array,
> Array, true)

I add them like this :

Di.xml :

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Model\Category\DataProvider" type="Designit\MegaMenu2\Model\Category\DataProvider" />
</config

Deleting this preference does clear out the error but i'm not sure if it will still work.

DataProvider :

<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Designit\MegaMenu2\Model\Category;

/**
 * Class DataProvider
 *
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class DataProvider extends \Magento\Catalog\Model\Category\DataProvider
{
    /**
     * @return array
     */
    protected function getFieldsMap()
    {
        return [
            'general' =>
                [
                    'parent',
                    'path',
                    'is_active',
                    'include_in_menu',
                    'name',
                ],
            'content' =>
                [
                    'image',
                    'description',
                    'landing_page',
                ],
            'display_settings' =>
                [
                    'display_mode',
                    'is_anchor',
                    'available_sort_by',
                    'use_config.available_sort_by',
                    'default_sort_by',
                    'use_config.default_sort_by',
                    'filter_price_range',
                    'use_config.filter_price_range',
                ],
            'search_engine_optimization' =>
                [
                    'url_key',
                    'url_key_create_redirect',
                    'use_default.url_key',
                    'url_key_group',
                    'meta_title',
                    'meta_keywords',
                    'meta_description',
                ],
            'assign_products' =>
                [
                ],
            'design' =>
                [
                    'custom_use_parent_settings',
                    'custom_apply_to_products',
                    'custom_design',
                    'page_layout',
                    'custom_layout_update',
                ],
            'schedule_design_update' =>
                [
                    'custom_design_from',
                    'custom_design_to',
                ],
            'category_view_optimization' =>
                [
                ],
            'category_permissions' =>
                [
                ],
            'mega-menu' =>
                [
                    'enable_megamenu',
                    'megamenu_columns',
                    'megamenu_labels'
                ],
        ];
    }
}

Not entirely sure what this adds since i can't find docs but it seemed necessary to me. Can someone explain this?

I install the data like this (InstallData) :

<?php

namespace Designit\Megamenu2\Setup;

use Magento\Framework\Module\Setup\Migration;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Catalog\Setup\CategorySetupFactory;


class InstallData implements InstallDataInterface
{

    private $categorySetupFactory;

    public function __construct(CategorySetupFactory $categorySetupFactory)
    {
        $this->categorySetupFactory = $categorySetupFactory;
    }


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

        $installer->startSetup();

        $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
        $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Category::ENTITY);
        $attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId);

        $menu_attributes = ['enable_megamenu' => [
            'type' => 'int',
            'label' => 'Enable Mega Menu',
            'input' => 'boolean',
            'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
            'visible' => true,
            'default' => '0',
            'required' => false,
            'sort_order' => 100,
            'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'group' => 'Mega Menu',
            ],
            'megamenu_columns' => [
                'type' => 'varchar',
                'label' => 'Number of Columns',
                'input' => 'select',
                'source' => 'Designit\MegaMenu2\Model\Attribute\Columns',
                'required' => false,
                'sort_order' => 101,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'group' => 'Mega Menu',
            ],
            'megamenu_labels' => [
                'type' => 'varchar',
                'label' => 'Category Label',
                'input' => 'select',
                'source' => 'Designit\MegaMenu2\Model\Attribute\Labels',
                'required' => false,
                'sort_order' => 102,
                'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'group' => 'Mega Menu'
            ]
        ];


        foreach ($menu_attributes as $item => $data) {
            $categorySetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, $item, $data);
        }

        $idg = $categorySetup->getAttributeGroupId($entityTypeId, $attributeSetId, 'Mega Menu');

        foreach ($menu_attributes as $item => $data) {
            $categorySetup->addAttributeToGroup(
                $entityTypeId,
                $attributeSetId,
                $idg,
                $item,
                $data['sort_order']
            );
        }

        $installer->endSetup();
    }
}

This is confusing with the docs. I'm adding my own attribute group and i do not see to find any documentation about adding a new group. However i do know that Eavcategory is not used since 2.1.0 even though it still says it in the docs.

And last but not least i have my XML to show them in the page :

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="designit_megamenu">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Mega Menu</item>
                <item name="collapsible" xsi:type="boolean">true</item>
                <item name="sortOrder" xsi:type="number">100</item>
                <item name="componentType" xsi:type="string">fieldset</item>
            </item>
        </argument>
        <field name="enable_megamenu">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">1</item>
                    <item name="dataType" xsi:type="string">boolean</item>
                    <item name="formElement" xsi:type="string">checkbox</item>
                    <item name="label" xsi:type="string" translate="true">Enable MegaMenu</item>
                    <item name="prefer" xsi:type="string">toggle</item>
                    <item name="valueMap" xsi:type="array">
                        <item name="true" xsi:type="string">1</item>
                        <item name="false" xsi:type="string">0</item>
                    </item>
                    <item name="default" xsi:type="number">0</item>
                </item>
            </argument>
        </field>
        <field name="megamenu_columns">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Designit\MegaMenu2\Model\Attribute\Columns</item>
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">2</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="label" xsi:type="string" translate="true">Number of Columns</item>
                </item>
            </argument>
        </field>
        <field name="megamenu_labels">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Designit\MegaMenu2\Model\Attribute\Labels</item>
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">3</item>
                    <item name="dataType" xsi:type="string">string</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="label" xsi:type="string" translate="true">Category Label</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

I know that Magento has changed a lot about this in the last couple of versions but any help at all with this error with really help me out!

Thanks

1 Answer 1

0

I solved this by just not using another DataProvider. Doesn't seem to have disadvantages to far.

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.