Magento 2 : Face Error while create a custom block
-
09-03-2021 - |
Domanda
I got the below error when create the Custom Block for the HTML sitemap.
Error filtering template: Warning: Declaration of Vapor\Sitemap\Block\Sitemap\Category::_getHtml(Magento\Framework\Data\Tree\Node $menuTree, $childrenWrapClass, $limit, $colBrakes = Array) should be compatible with Magento\Theme\Block\Html\Topmenu::_getHtml(Magento\Framework\Data\Tree\Node $menuTree, $childrenWrapClass, $limit, array $colBrakes = Array) in C:\xampp\htdocs\Magento\app\code\Vapor\Sitemap\Block\Sitemap\Category.php on line 62
Block Code
<?php
namespace Vapor\Sitemap\Block\Sitemap;
// use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\Element\Template;
// use Vapor\Sitemap\Model\Sitemap\CmsPages;
// use Vapor\Sitemap\Block\Sitemap\Cms;
// use Vapor\Sitemap\Block\Sitemap\Category;
class Index extends Template
{
const SITEMAP_CUSTOM_TEMPLATE = 'Vapor_Sitemap::sitemap/sitemap.phtml';
/**
* [__construct]
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Stdlib\DateTime\Timezone $_stdTimezone [description]
* @param array $data
*/
protected $getSitemap;
public function __construct(\Magento\Framework\View\Element\Template\Context $context,\Magento\Framework\Stdlib\DateTime\Timezone $_stdTimezone,
array $data = [])
{
parent::__construct($context, $data);
$this->getSitemap();
}
/**
*
* @return html
*/
protected function _toHtml()
{
return parent::_toHtml();
}
/**
* @return Mixed data
*/
public function getSitemap()
{
//echo "ComeHere";exit;
$this->setTemplate(self::SITEMAP_CUSTOM_TEMPLATE);
return $this;
}
}
Can anyone help to solve this.
Any help would be appreciated.
Thanks in advance..!
Soluzione
make your _getHtml
method from the class Vapor\Sitemap\Block\Sitemap\Category
look like this:
protected function _getHtml(
\Magento\Framework\Data\Tree\Node $menuTree,
$childrenWrapClass,
$limit,
array $colBrakes = []
) {
.....
}
you are missing a type hint array
on the last parameter