29 lines
672 B
PHP
29 lines
672 B
PHP
<?php
|
|
/**
|
|
* Force the catalog top navigation to use the Esun mega menu template.
|
|
*/
|
|
namespace Esun\MegaMenu\Plugin;
|
|
|
|
use Esun\MegaMenu\ViewModel\MegaMenuData;
|
|
use Magento\Theme\Block\Html\Topmenu;
|
|
|
|
class TopmenuTemplatePlugin
|
|
{
|
|
private $megaMenuData;
|
|
|
|
public function __construct(MegaMenuData $megaMenuData)
|
|
{
|
|
$this->megaMenuData = $megaMenuData;
|
|
}
|
|
|
|
public function beforeToHtml(Topmenu $subject): void
|
|
{
|
|
if ($subject->getNameInLayout() !== 'catalog.topnav') {
|
|
return;
|
|
}
|
|
|
|
$subject->setData('view_model', $this->megaMenuData);
|
|
$subject->setTemplate('Esun_MegaMenu::html/topmenu.phtml');
|
|
}
|
|
}
|