Skip to content

Commit

Permalink
Merge branch 'release/2.27.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwaclawczyk committed Aug 5, 2024
2 parents 0e1e811 + b324193 commit 2ac08c5
Show file tree
Hide file tree
Showing 60 changed files with 927 additions and 643 deletions.
46 changes: 44 additions & 2 deletions Api/Data/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ interface NodeInterface
const TARGET = 'target';
const IMAGE = 'image';
const IMAGE_ALT_TEXT = 'image_alt_text';
const IMAGE_WIDTH = 'image_width';
const IMAGE_HEIGHT = 'image_heigth';
const CREATION_TIME = 'creation_time';
const UPDATE_TIME = 'update_time';
const IS_ACTIVE = 'is_active';
const ADDITIONAL_DATA = 'additional_data';
const SELECTED_ITEM_ID = 'selected_item_id';
const CUSTOMER_GROUPS = 'customer_groups';

/**
* Get node id
Expand Down Expand Up @@ -192,18 +195,40 @@ public function setImage($image);
/**
* Get image alt text
*
* @return string
* @return string|null
*/
public function getImageAltText();

/**
* Set image alt text
*
* @param string $altText
* @param string|null $altText
* @return $this
*/
public function setImageAltText($altText);

/**
* @return int|null
*/
public function getImageWidth();

/**
* @param int|null $width
* @return $this
*/
public function setImageWidth($width);

/**
* @return int|null
*/
public function getImageHeight();

/**
* @param int|null $height
* @return $this
*/
public function setImageHeight($height);

/**
* Get creation time
*
Expand Down Expand Up @@ -274,4 +299,21 @@ public function getSelectedItemId();
* @return $this
*/
public function setSelectedItemId($selectedItemId);

/**
* Get customer groups
*
*/
public function getCustomerGroups();

/**
* @return $this
*/
public function setCustomerGroups($customerGroups);

/**
* @param int $customerGroupId
* @return bool
*/
public function isVisible($customerGroupId);
}
18 changes: 17 additions & 1 deletion Block/Adminhtml/Edit/Tab/Nodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Magento\Framework\Registry;
use Snowdog\Menu\Api\NodeRepositoryInterface;
use Snowdog\Menu\Controller\Adminhtml\Menu\Edit;
use Snowdog\Menu\Model\CustomerGroupsProvider;
use Snowdog\Menu\Model\Menu\Node\Image\File as ImageFile;
use Snowdog\Menu\Model\NodeTypeProvider;
use Snowdog\Menu\Model\VueProvider;
Expand Down Expand Up @@ -45,13 +46,19 @@ class Nodes extends Template implements TabInterface
*/
private $vueProvider;

/**
* @var CustomerGroupsProvider
*/
private $customerGroupsProvider;

public function __construct(
Template\Context $context,
NodeRepositoryInterface $nodeRepository,
ImageFile $imageFile,
NodeTypeProvider $nodeTypeProvider,
Registry $registry,
VueProvider $vueProvider,
CustomerGroupsProvider $customerGroupsProvider,
array $data = []
) {
parent::__construct($context, $data);
Expand All @@ -60,6 +67,7 @@ public function __construct(
$this->nodeTypeProvider = $nodeTypeProvider;
$this->imageFile = $imageFile;
$this->vueProvider = $vueProvider;
$this->customerGroupsProvider = $customerGroupsProvider;
}

public function renderNodes()
Expand Down Expand Up @@ -182,8 +190,11 @@ private function renderNodeList($level, $parent, $data)
'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()
'selected_item_id' => $node->getSelectedItemId(),
'customer_groups' => $node->getCustomerGroups()
];
}
return $menu;
Expand All @@ -206,4 +217,9 @@ public function getVueComponents(): array
{
return $this->vueProvider->getComponents();
}

public function getCustomerGroups()
{
return $this->customerGroupsProvider->getAll();
}
}
53 changes: 34 additions & 19 deletions Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Snowdog\Menu\Block;

use Magento\Framework\Api\Search\FilterGroupBuilder;
use Magento\Framework\Api\Search\SearchCriteriaFactory;
use Magento\Framework\App\Cache\Type\Block;
use Magento\Framework\App\Http\Context;
use Magento\Framework\DataObject;
use Magento\Framework\View\Element\Template;
use Magento\Framework\Event\Manager as EventManager;
use Magento\Framework\Escaper;
use Snowdog\Menu\Api\Data\NodeInterface;
use Snowdog\Menu\Api\MenuRepositoryInterface;
use Snowdog\Menu\Api\NodeRepositoryInterface;
use Snowdog\Menu\Model\Menu\Node\Image\File as ImageFile;
Expand All @@ -18,9 +18,13 @@

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Menu extends Template implements DataObject\IdentityInterface
{
const XML_SNOWMENU_GENERAL_CUSTOMER_GROUPS = 'snowmenu/general/customer_groups';

/**
* @var MenuRepositoryInterface
*/
Expand All @@ -40,15 +44,6 @@ class Menu extends Template implements DataObject\IdentityInterface

private $menu = null;

/**
* @var SearchCriteriaFactory
*/
private $searchCriteriaFactory;

/**
* @var FilterGroupBuilder
*/
private $filterGroupBuilder;
/**
* @var EventManager
*/
Expand Down Expand Up @@ -84,6 +79,11 @@ class Menu extends Template implements DataObject\IdentityInterface
*/
private $escaper;

/**
* @var Context
*/
private $httpContext;

/**
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand All @@ -93,25 +93,23 @@ public function __construct(
MenuRepositoryInterface $menuRepository,
NodeRepositoryInterface $nodeRepository,
NodeTypeProvider $nodeTypeProvider,
SearchCriteriaFactory $searchCriteriaFactory,
FilterGroupBuilder $filterGroupBuilder,
TemplateResolver $templateResolver,
ImageFile $imageFile,
Escaper $escaper,
Context $httpContext,
array $data = []
) {
parent::__construct($context, $data);
$this->menuRepository = $menuRepository;
$this->nodeRepository = $nodeRepository;
$this->nodeTypeProvider = $nodeTypeProvider;
$this->searchCriteriaFactory = $searchCriteriaFactory;
$this->filterGroupBuilder = $filterGroupBuilder;
$this->eventManager = $eventManager;
$this->templateResolver = $templateResolver;
$this->imageFile = $imageFile;
$this->escaper = $escaper;
$this->setTemplate($this->getMenuTemplate($this->_template));
$this->submenuTemplate = $this->getSubmenuTemplate();
$this->httpContext = $httpContext;
}

/**
Expand Down Expand Up @@ -177,6 +175,9 @@ public function getCacheKeyInfo()
if ($nodeCacheKeyInfo) {
$info = array_merge($info, $nodeCacheKeyInfo);
}
if ($this->_scopeConfig->isSetFlag(self::XML_SNOWMENU_GENERAL_CUSTOMER_GROUPS)) {
$info[] = 'cust_group_' . $this->getCustomerGroupId();
}

return $info;
}
Expand Down Expand Up @@ -268,7 +269,7 @@ public function isViewAllLinkAllowed($nodeType)
}

/**
* @param NodeRepositoryInterface $node
* @param NodeInterface $node
* @return string
*/
public function renderViewAllLink($node)
Expand All @@ -279,7 +280,7 @@ public function renderViewAllLink($node)
}

/**
* @param NodeRepositoryInterface $node
* @param NodeInterface $node
* @return string
*/
public function renderMenuNode($node)
Expand Down Expand Up @@ -381,7 +382,7 @@ public function getMenuCssClass($defaultClass = '')
}

/**
* @param NodeRepositoryInterface $node
* @param NodeInterface $node
* @return Template
*/
private function getMenuNodeBlock($node)
Expand All @@ -404,9 +405,13 @@ private function getMenuNodeBlock($node)
->setImage($node->getImage())
->setImageUrl($node->getImage() ? $this->imageFile->getUrl($node->getImage()) : null)
->setImageAltText($node->getImageAltText())
->setImageWidth($node->getImageWidth())
->setImageHeight($node->getImageHeight())
->setImageAltText($node->getImageAltText())
->setCustomTemplate($node->getNodeTemplate())
->setAdditionalData($node->getAdditionalData())
->setSelectedItemId($node->getSelectedItemId());
->setSelectedItemId($node->getSelectedItemId())
->setCustomerGroups($node->getCustomerGroups());

return $nodeBlock;
}
Expand Down Expand Up @@ -438,12 +443,17 @@ private function getSubmenuBlock($nodes, $parentNode, $level = 0)
private function fetchData()
{
$nodes = $this->nodeRepository->getByMenu($this->loadMenu()->getId());
$currentCustomerGroup = $this->getCustomerGroupId();
$customerGroupEnabled = $this->_scopeConfig->getValue(self::XML_SNOWMENU_GENERAL_CUSTOMER_GROUPS);
$result = [];
$types = [];
foreach ($nodes as $node) {
if (!$node->getIsActive()) {
continue;
}
if ($customerGroupEnabled && !$node->isVisible($currentCustomerGroup)) {
continue;
}

$level = $node->getLevel();
$parent = $node->getParentId() ?: 0;
Expand Down Expand Up @@ -498,4 +508,9 @@ private function getSubmenuTemplate()

return $this->getMenuTemplate($baseSubmenuTemplate);
}

public function getCustomerGroupId()
{
return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP);
}
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [2.27.0]
### Added
- `width` and `height` attributes to menu node images (DEV-102271)
- Option to specify customer groups for each node (DEV-94738)
- Snowdog branding in admin panel (DEV-105762)
- Automatically open collapsed menu node when dragging another node inside (DEV-101986)
- Duplicate node functionality (DEV-104364)
### Fixed
- Impossible to change Cms block, Cms page link after selecting displayed block (DEV-104546)
- Submenu template name issue ([#321](https://github.com/SnowdogApps/magento2-menu/pull/321)) (DEV-105672)
- Issue with 'Import from Categories ([#315](https://github.com/SnowdogApps/magento2-menu/issues/315)) (DEV-105267 & DEV-101741)
### Updated
- vue-select to 3.20.0 (DEV-104546)

## [2.26.0] - 2024-03-29
### Fixed
- The function getProductTitle() returns empty string (DEV-104749)
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Menu/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function execute(): ResultInterface
$resultPage = $this->resultPageFactory->create();
$title = $menuId ? __('Edit Menu %1', $menu->getTitle()) : __('New Menu');
$this->initPage($resultPage)->addBreadcrumb($title, $title);
$resultPage->getConfig()->getTitle()->prepend(__('Menus'));
$resultPage->getConfig()->getTitle()->prepend(__('Snowdog Menus'));
$resultPage->getConfig()->getTitle()->prepend($menu->getId() ? $menu->getTitle() : __('New Menu'));

return $resultPage;
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Menu/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function execute()
$this->messageManager->addNoticeMessage($this->importExportHelper->getMaxUploadSizeMessage());

$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->getConfig()->getTitle()->prepend(__('Snowdog Menus'));
$resultPage->getConfig()->getTitle()->prepend(__('Menu Import'));

return $resultPage;
Expand Down
15 changes: 9 additions & 6 deletions Controller/Adminhtml/Menu/ImportCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Snowdog\Menu\Controller\Adminhtml\Menu;

use Exception;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Snowdog\Menu\Api\MenuManagementInterface;
use Magento\Framework\Exception\NoSuchEntityException;

class ImportCategories extends Action implements HttpPostActionInterface
{
Expand Down Expand Up @@ -47,24 +47,27 @@ public function execute()
{
$categoryId = (int) $this->_request->getParam('category_id');
$depth = $this->_request->getParam('depth');
if (!is_numeric($depth)) {
$depth = null;
}

$result = $this->resultJsonFactory->create();
try {
if ($depth != 'NaN' && !is_numeric($depth)) {
throw new Exception('Please add a valid number for Level of depth field');
}

$categoryTree = $this->menuManagement->getCategoryNodeList($categoryId, $depth);

$output = [
'success' => 1,
'list' => $categoryTree
];
} catch (NoSuchEntityException $exception) {
} catch (Exception $exception) {
$output = [
'success' => 0,
'message' => $exception->getMessage(),
'list' => []
];
}

$result = $this->resultJsonFactory->create();
$result->setData($output);

return $result;
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Menu/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Index extends Action
public function execute()
{
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->getConfig()->getTitle()->prepend(__('Menus'));
$resultPage->getConfig()->getTitle()->prepend(__('Snowdog Menus'));
return $resultPage;
}
}
Loading

0 comments on commit 2ac08c5

Please sign in to comment.