magento2-menu
magento2-menu copied to clipboard
Dx improvments
Hello,
first of all, thank you for this very complete module. We have started to integrate it in our magento 2 and we have 2 minor proposals that can greatly improve the developer experience.
For the context, we had to add 2 fields to the menu nodes. To do this, we had to override Node, which was done without a hitch, but we also had to copy/paste the following classes entirely:
- SnowdogMenuBlockAdminhtmlEditTabNodes
- \SnowdogMenuServiceMenuSaveRequestProcessor
but also the following template:
- app/design/adminhtml/Turquand/backend/Snowdog_Menu/templates/menu/nodes.phtml
\Snowdog_MenuBlock\AdminhtmlEdit\Tab\Nodes
So, for this class, would it be possible to modify it slightly by doing something like :
class Nodes
{
// prefix template with module name. Allow us to load the original template even if we defined a preference.
protected $_template = 'Snowdog_Menu::menu/nodes.phtml';
/**
* @var Registry
*/
protected $registry;
/**
* @var NodeRepositoryInterface
*/
protected $nodeRepository;
/**
* @var ImageFile
*/
protected $imageFile;
/**
* @var NodeTypeProvider
*/
protected $nodeTypeProvider;
/**
* @var VueProvider
*/
protected $vueProvider;
/**
* @var CustomerGroupsProvider
*/
protected $customerGroupsProvider;
// ...
private function renderNodeList($level, $parent, $data)
{
if ($parent === null) {
$parent = 0;
}
if (empty($data[$level])) {
return;
}
if (empty($data[$level][$parent])) {
return;
}
$nodes = $data[$level][$parent];
$menu = [];
foreach ($nodes as $node) {
$menu[] = $this->renderNode($node, $parent, $level, $data);
}
return $menu;
}
protected function renderNode($node, $parent, $level, $data)
{
return [
'is_active' => $node->getIsActive(),
'is_stored' => true,
'type' => $node->getType(),
'content' => $node->getContent(),
'classes' => $node->getClasses(),
'target' => $node->getTarget(),
'node_template' => $node->getNodeTemplate(),
'submenu_template' => $node->getSubmenuTemplate(),
'id' => $node->getId(),
'title' => $node->getTitle(),
'image' => $node->getImage(),
'image_url' => $node->getImage() ? $this->imageFile->getUrl($node->getImage()) : null,
'image_alt_text' => $node->getImageAltText(),
'image_width' => $node->getImageWidth(),
'image_height' => $node->getImageHeight(),
'columns' => $this->renderNodeList($level + 1, $node->getId(), $data) ?: [],
'selected_item_id' => $node->getSelectedItemId(),
'customer_groups' => $node->getCustomerGroups()
];
}
}
This would make it easy to override node serialization via a preference.
\Snowdog\Menu\ServiceMenu\SaveRequestProcessor
For this class, would it be possible to make the properties and processNodeObject method protected ? This would make it easy to override the entity's valuation via a preference.