Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Added active page flag for menu items
givanz2873505a3182
diff --git a/app/component/menu.php b/app/component/menu.phpindex f73430f..384ec64 100755--- a/app/component/menu.php+++ b/app/component/menu.php@@ -22,6 +22,7 @@namespace Vvveb\Component;+use function Vvveb\getCurrentUrl;use function Vvveb\sanitizeHTML;use Vvveb\Sql\menuSQL;use Vvveb\Sql\postSQL;@@ -48,7 +49,6 @@ class Menu extends ComponentBase {$menuSql = new menuSQL();$results = $menuSql->getMenus($options);- $current_category_slug = false;//count the number of child menus (subcategories) for each categoryif (isset($results['menus'])) {@@ -59,12 +59,6 @@ class Menu extends ComponentBase {$parent_id = $category['parent_id'] ?? false;$type = $category['type'] ?? 'link';- if ($current_category_slug == $category['slug']) {- $category['active'] = true;- } else {- $category['active'] = false;- }-if (! isset($category['children'])) {$category['children'] = 0;}@@ -107,11 +101,11 @@ class Menu extends ComponentBase {$productTaxonomy = array_flip($productIds);foreach ($products['products'] as $product) {- $taxonomy_item_id = $productTaxonomy[$product['product_id']];- $category = &$results['menus'][$taxonomy_item_id];- $route = "product/{$category['type']}/index";- $category['url'] = url($route, ['slug'=> $product['slug']]);- $category['name'] = $product['name'];+ $taxonomy_item_id = $productTaxonomy[$product['product_id']];+ $category = &$results['menus'][$taxonomy_item_id];+ $route = "product/{$category['type']}/index";+ $category['url'] = url($route, ['slug'=> $product['slug']]);+ $category['name'] = $product['name'];}}}@@ -146,6 +140,19 @@ class Menu extends ComponentBase {return $results;}+ //called on each request+ function request(&$results, $index = 0) {+ $currentUrl = getCurrentUrl();++ if (isset($results['menus'])) {+ foreach ($results['menus'] as $taxonomy_item_id => &$category) {+ $category['active'] = ($category['url'] === $currentUrl);+ }+ }++ return $results;+ }+//called by editor on page save for each component on page//this method is called from admin appstatic function editorSave($id, $fields, $type = 'menu') {diff --git a/app/template/components/menu.tpl b/app/template/components/menu.tplindex 7c30c7c..5292961 100755--- a/app/template/components/menu.tpl+++ b/app/template/components/menu.tpl@@ -48,7 +48,7 @@ if (isset($this->_component['menu']) && isset($this->_component['menu'][$_menu_i@category [data-v-menu-item-img]|src = $category['images'][0]@category|append = <?php- if ($category['children'] > 0) {+ if ($category['children'] > 0 && $generate_menu) {$parents++;$generate_menu($category['menu_item_id'], $_categories);}@@ -69,4 +69,4 @@ $generate_menu = function ($parent_id) use (&$_categories, &$generate_menu, &$pa@category-recursive|after = <?php}-?>+?>\ No newline at end of file