0

I am getting this error:

Warning: Declaration of MGS\Amp\Block\Html\Topmenu::_getHtml(Magento\Framework\Data\Tree\Node $menuTree, $childrenWrapClass, $limit, array $colBrakes = Array) should be compatible with Magento\Theme\Block\Html\Topmenu::_gethtml(Magento\Framework\Data\Tree\Node $menuTree, $childrenWrapClass, $limit, $colBrakes = Array) in /var/www/vhosts/fakedomain.com/httpdocs/app/code/MGS/Amp/Block/Html/Topmenu.php on line 105 

I get this error when trying to run the command - bin/magento setup:di:compile

I am trying to do this because even after I have the theme installed when i got to the home page i get an error. Those logs are saying:

Object DOMDocument should be created.";i:1;s:13313:"#0 /var/www/vhosts/fakedomain.com/httpdocs/vendor/magento/framework/View/Element/UiComponent/Config/Reader.php(95):

Any help would be appreciated in this.

EDIT:

here is the code from that file:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace MGS\Amp\Block\Html;

use Magento\Framework\Data\Tree\Node;
use Magento\Framework\Data\Tree\NodeFactory;
use Magento\Framework\Data\TreeFactory;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\View\Element\Template;

/**
 * Html page top menu block
 *
 * @api
 * @since 100.0.2
 */
class Topmenu extends \Magento\Theme\Block\Html\Topmenu
{
    /**
     * Cache identities
     *
     * @var array
     */
    protected function _getHtml(
        \Magento\Framework\Data\Tree\Node $menuTree,
        $childrenWrapClass,
        $limit,
        array $colBrakes = []
    ) {
        $html = '';

        $children = $menuTree->getChildren();
        $parentLevel = $menuTree->getLevel();
        $childLevel = $parentLevel === null ? 0 : $parentLevel + 1;

        $counter = 1;
        $itemPosition = 1;
        $childrenCount = $children->count();

        $parentPositionClass = $menuTree->getPositionClass();
        $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';

        /** @var \Magento\Framework\Data\Tree\Node $child */
        foreach ($children as $child) {
            if ($childLevel === 0 && $child->getData('is_parent_active') === false) {
                continue;
            }
            $child->setLevel($childLevel);
            $child->setIsFirst($counter == 1);
            $child->setIsLast($counter == $childrenCount);
            $child->setPositionClass($itemPositionClassPrefix . $counter);

            $outermostClassCode = '';
            $outermostClass = $menuTree->getOutermostClass();

            if ($childLevel == 0 && $outermostClass) {
                $outermostClassCode = ' class="' . $outermostClass . '" ';
                $currentClass = $child->getClass();

                if (empty($currentClass)) {
                    $child->setClass($outermostClass);
                } else {
                    $child->setClass($currentClass . ' ' . $outermostClass);
                }
            }

            if (is_array($colBrakes) && count($colBrakes) && $colBrakes[$counter]['colbrake']) {
                $html .= '</ul></li><li class="column"><ul>';
            }

            if($this->_addSubMenu(
                $child,
                $childLevel,
                $childrenWrapClass,
                $limit
            )) {
                $html .= '<amp-accordion ' . $this->_getRenderedMenuItemAttributes($child) . '>';
                $html .= '<section><h6>' . $this->escapeHtml(
                        $child->getName()
                    ) . '</h6>' . $this->_addSubMenu(
                        $child,
                        $childLevel,
                        $childrenWrapClass,
                        $limit
                    ) . '</section></amp-accordion>';
            } else {
                $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml(
                        $child->getName()
                    ) . '</span></a>';
            }

            $itemPosition++;
            $counter++;
        }

        if (is_array($colBrakes) && count($colBrakes) && $limit) {
            $html = '<li class="column"><ul>' . $html . '</ul></li>';
        }

        return $html;
    }
}
0

here is the code from that file:

use Magento\Framework\Data\Tree\Node; use Magento\Framework\Data\Tree\NodeFactory; use Magento\Framework\Data\TreeFactory; use Magento\Framework\DataObject\IdentityInterface; use Magento\Framework\View\Element\Template;

/** * Html page top menu block * * @api * @since 100.0.2 */ class Topmenu extends \Magento\Theme\Block\Html\Topmenu { /** * Cache identities * * @var array */ protected function _getHtml( \Magento\Framework\Data\Tree\Node $menuTree, $childrenWrapClass, $limit, array $colBrakes = [] ) { $html = '';

    $children = $menuTree->getChildren();
    $parentLevel = $menuTree->getLevel();
    $childLevel = $parentLevel === null ? 0 : $parentLevel + 1;

    $counter = 1;
    $itemPosition = 1;
    $childrenCount = $children->count();

    $parentPositionClass = $menuTree->getPositionClass();
    $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';

    /** @var \Magento\Framework\Data\Tree\Node $child */
    foreach ($children as $child) {
        if ($childLevel === 0 && $child->getData('is_parent_active') === false) {
            continue;
        }
        $child->setLevel($childLevel);
        $child->setIsFirst($counter == 1);
        $child->setIsLast($counter == $childrenCount);
        $child->setPositionClass($itemPositionClassPrefix . $counter);

        $outermostClassCode = '';
        $outermostClass = $menuTree->getOutermostClass();

        if ($childLevel == 0 && $outermostClass) {
            $outermostClassCode = ' class="' . $outermostClass . '" ';
            $currentClass = $child->getClass();

            if (empty($currentClass)) {
                $child->setClass($outermostClass);
            } else {
                $child->setClass($currentClass . ' ' . $outermostClass);
            }
        }

        if (is_array($colBrakes) && count($colBrakes) && $colBrakes[$counter]['colbrake']) {
            $html .= '</ul></li><li class="column"><ul>';
        }

        if($this->_addSubMenu(
            $child,
            $childLevel,
            $childrenWrapClass,
            $limit
        )) {
            $html .= '<amp-accordion ' . $this->_getRenderedMenuItemAttributes($child) . '>';
            $html .= '<section><h6>' . $this->escapeHtml(
                    $child->getName()
                ) . '</h6>' . $this->_addSubMenu(
                    $child,
                    $childLevel,
                    $childrenWrapClass,
                    $limit
                ) . '</section></amp-accordion>';
        } else {
            $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml(
                    $child->getName()
                ) . '</span></a>';
        }

        $itemPosition++;
        $counter++;
    }

    if (is_array($colBrakes) && count($colBrakes) && $limit) {
        $html = '<li class="column"><ul>' . $html . '</ul></li>';
    }

    return $html;
}

}

| improve this answer | |
  • Please remove this answer as I've updated your question with this file content. – Sumit May 15 at 3: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.