Skip to content

Commit

Permalink
Merge branch 'develop' into feature/100390
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarek Krupiński authored Jul 25, 2023
2 parents e9f4e8f + e4a5449 commit b515f01
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 56 deletions.
3 changes: 0 additions & 3 deletions Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ private function getNodeCacheKeyInfo()
$request = $this->getRequest();

switch ($request->getRouteName()) {
case 'cms':
$nodeType = 'cms_page';
break;
case 'catalog':
$nodeType = 'category';
break;
Expand Down
9 changes: 1 addition & 8 deletions Block/NodeType/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,12 @@ public function getCurrentCategory()
*/
public function getNodeCacheKeyInfo()
{
$info = [
return [
'module_' . $this->getRequest()->getModuleName(),
'controller_' . $this->getRequest()->getControllerName(),
'route_' . $this->getRequest()->getRouteName(),
'action_' . $this->getRequest()->getActionName()
];

$category = $this->getCurrentCategory();
if ($category) {
$info[] = 'category_' . $category->getId();
}

return $info;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions Block/NodeType/CategoryChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,12 @@ public function __construct(
*/
public function getNodeCacheKeyInfo()
{
$info = [
return [
'module_' . $this->getRequest()->getModuleName(),
'controller_' . $this->getRequest()->getControllerName(),
'route_' . $this->getRequest()->getRouteName(),
'action_' . $this->getRequest()->getActionName()
];
$category = $this->getCurrentCategory();
if ($category) {
$info[] = 'category-child_' . $category->getId();
}

return $info;
}

/**
Expand Down
15 changes: 0 additions & 15 deletions Block/NodeType/CmsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,6 @@ public function __construct(
$this->storesList = $storeManager->getStores();
}

/**
* @return array
*/
public function getNodeCacheKeyInfo()
{
$info = [];
$pageId = $this->getRequest()->getParam('page_id');

if ($pageId) {
$info[] = 'cms_page_' . $pageId;
}

return $info;
}

/**
* @inheritDoc
*/
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Update GH actions to github-actions-m2 and small code fixes to standards (#100322)
- Don't show <a> tag when there's no url (DEV-100390)
- Fixed issue about menu block being cached excessively ([#276](https://github.com/SnowdogApps/magento2-menu/issues/276))

## [2.22.0] - 2023-05-08
### Fixed
Expand Down
8 changes: 8 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable no-unused-vars */
var config = {
map: {
'*': {
'menu': 'Snowdog_Menu/js/menu.babel'
}
}
};
5 changes: 4 additions & 1 deletion view/frontend/templates/menu.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
</svg>
</div>

<nav class="<?= $menuClass ?>">
<nav
class="<?= $menuClass ?>"
data-mage-init='{"menu": {}}'
>
<ul class="<?= $menuClass ?>__list">
<?php foreach ($block->getNodes() as $node): ?>
<?php
Expand Down
4 changes: 0 additions & 4 deletions view/frontend/templates/menu/node_type/category.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ if ($block->getIsViewAllLink()) {
if ($nodeId) {
$dataAttribute = ' data-menu="menu-' . $nodeId . '"';
}

if ($block->isCurrentCategory($nodeId)) {
$classLink .= ' current';
}
}
?>

Expand Down
5 changes: 0 additions & 5 deletions view/frontend/templates/menu/node_type/cms_page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ if ($block->getIsViewAllLink()) {
if ($nodeId) {
$dataAttribute = ' data-menu="menu-' . $nodeId . '"';
}

if ($block->isCurrentPage($nodeId)) {
$classLink .= ' current';
}
}
?>

<a
Expand Down
4 changes: 0 additions & 4 deletions view/frontend/templates/menu/node_type/product.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ $imageAltText = $block->getImageAltText();
if ($nodeId) {
$dataAttribute = ' data-menu="menu-' . $nodeId . '"';
}

if ($block->isCurrentProduct($nodeId)) {
$classLink .= ' current';
}
?>

<a
Expand Down
27 changes: 27 additions & 0 deletions view/frontend/web/js/menu.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
define([], function () {
'use strict';

class Menu {
constructor(element) {
this.menu = element;
this.links = this.menu.querySelectorAll('a');
this.path = window.location.href;

if (this.links.length) {
this.setCurrentItem();
}
}

setCurrentItem() {
this.links.forEach((link) => {
if (this.path === link.getAttribute('href')) {
link.classList.add('current');
}
});
}
}

return function (config, element) {
new Menu(element);
};
});
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,14 @@ rimraf@^3.0.2:
glob "^7.1.3"

semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.2.1:
version "7.3.5"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"

Expand Down Expand Up @@ -714,9 +714,9 @@ which@^2.0.1:
isexe "^2.0.0"

word-wrap@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==
version "1.2.4"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f"
integrity sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==

wrappy@1:
version "1.0.2"
Expand Down

0 comments on commit b515f01

Please sign in to comment.