Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dx improvments #340

Open
mokabiwd opened this issue Aug 30, 2024 · 1 comment
Open

Dx improvments #340

mokabiwd opened this issue Aug 30, 2024 · 1 comment

Comments

@mokabiwd
Copy link

mokabiwd commented Aug 30, 2024

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.

@andrzejborkowski
Copy link

hi @mokabiwd,

we'd appreciate if you can create a PR and then our dev team will review it and if everything is clear we can include this improvement to the one of the next releases. Thanks in advance!

Regards,
Andrzej

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants