0

I have created a custom menu link using few examples one of them is:Adding a non-category link to the navigation links in magento 2

This is how I've added first level menu:

        ...
        $firstNode = $this->nodeFactory->create(
            [
                'data' => [
                    'name' => __('Level One'),
                    'id' => 'suppliers',
                    'url' => '/test-level-one',
                    'has_active' => false,
                    'is_active' => false // (expression to determine if menu item is selected or not)
                ],
                'idField' => 'id',
                'tree' => $subject->getMenu()->getTree()
            ]
        );

        $subject->getMenu()->addChild($firstNode);
       ...

Now to add a submenu I've added like so:

 $secondNode = $this->nodeFactory->create(
            [
                'data' => [
                    'name' => __('Level Two'),
                    'id' => 'test_id',
                    'url' => '/this-is-just-a-test-url',
                    'has_active' => false,
                    'is_active' => false // (expression to determine if menu item is selected or not)
                ],
                'idField' => 'test_id',
                'tree' => $subject->getMenu()->getTree()
            ],
            [
                'data' => [
                    'name' => __('Another Level Two'),
                    'id' => 'test_another_id',
                    'url' => '/this-is-just-another-test-url',
                    'has_active' => false,
                    'is_active' => false // (expression to determine if menu item is selected or not)
                ],
                'idField' => 'test_another_id',
                'tree' => $subject->getMenu()->getTree()
            ]
        );
        $firstNode->addChild($secondNode);

But it only adds the first element in the array as submenu Level Two and not adding Another Level Two any one any idea any help appreciate in advance!

Your Answer

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

Browse other questions tagged or ask your own question.