Skip to content

Commit

Permalink
Get menu by link field
Browse files Browse the repository at this point in the history
  • Loading branch information
Martyna Maciejewska committed Jan 26, 2024
1 parent 261c712 commit 32ec3df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Service/Menu/SaveRequestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Snowdog\Menu\Api\Data\MenuInterface;
use Snowdog\Menu\Api\Data\NodeInterface;
use Snowdog\Menu\Api\NodeRepositoryInterface;
use Snowdog\Menu\Helper\MenuHelper;
use Snowdog\Menu\Model\Menu\Node\Image\File as NodeImageFile;
use Snowdog\Menu\Model\Menu\Node\Image\Node as ImageNode;
use Snowdog\Menu\Model\Menu\Node\Validator as NodeValidator;
Expand Down Expand Up @@ -52,14 +53,20 @@ class SaveRequestProcessor
*/
private $menuNodes;

/**
* @var MenuHelper
*/
private $menuHelper;

public function __construct(
ManagerInterface $messageManager,
NodeRepositoryInterface $nodeRepository,
NodeImageFile $nodeImageFile,
ImageNode $imageNode,
NodeValidator $nodeValidator,
NodeFactory $nodeFactory,
MenuNodes $menuNodes
MenuNodes $menuNodes,
MenuHelper $menuHelper
) {
$this->messageManager = $messageManager;
$this->nodeRepository = $nodeRepository;
Expand All @@ -68,6 +75,7 @@ public function __construct(
$this->nodeValidator = $nodeValidator;
$this->nodeFactory = $nodeFactory;
$this->menuNodes = $menuNodes;
$this->menuHelper = $menuHelper;
}

/**
Expand Down Expand Up @@ -106,7 +114,7 @@ public function saveData(MenuInterface $menu, array $nodes = []): void

if (!isset($invalidNodes[$nodeId])) {
$nodeObject = $this->nodeFactory->create();
$nodeObject->setData($menu->getLinkField(), $menu->getLinkValue());
$nodeObject->setData($this->menuHelper->getLinkField(), $this->menuHelper->getLinkValue($menu));
$nodeObject = $this->nodeRepository->save($nodeObject);
$nodeMap[$nodeId] = $nodeObject;
}
Expand Down
12 changes: 10 additions & 2 deletions Ui/Component/Listing/Column/MenuList/PageActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Framework\UrlInterface;
use Snowdog\Menu\Helper\MenuHelper;

/**
* Class PageActions
Expand All @@ -30,6 +31,11 @@ class PageActions extends Column
*/
private $urlBuilder;

/**
* @var MenuHelper
*/
private $menuHelper;

/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
Expand All @@ -38,12 +44,14 @@ class PageActions extends Column
* @param array $data
*/
public function __construct(
MenuHelper $menuHelper,
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
array $components = [],
array $data = []
) {
$this->menuHelper = $menuHelper;
$this->urlBuilder = $urlBuilder;
parent::__construct(
$context,
Expand All @@ -57,9 +65,9 @@ public function prepareDataSource(array $dataSource): array
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
if (isset($item['menu_id'])) {
if (isset($item[$this->menuHelper->getLinkField()])) {
$name = $this->getData('name');
$menuId = (int) $item['menu_id'];
$menuId = (int) $item[$this->menuHelper->getLinkField()];
$isActive = (int) $item['is_active'] === 1;
$item[$name] = [
'edit' => $this->getEditButton($menuId),
Expand Down

0 comments on commit 32ec3df

Please sign in to comment.