Files
new.rybstock.ru/views/partials/mega-category-menu.php
T
2026-06-07 13:12:42 +03:00

50 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
/** @var array<int, array<string, mixed>> $megaCategories */
require_once __DIR__ . '/category-icons.php';
if (!function_exists('render_mega_category_children')) {
/**
* @param array<int, array<string, mixed>> $children
*/
function render_mega_category_children(array $children, int $depth = 1): void
{
if ($children === [] || $depth > 3) {
return;
}
?>
<ul class="mega-submenu depth-<?= e((string) $depth) ?>">
<?php foreach ($children as $child): ?>
<li>
<a href="/catalog/<?= e((string) $child['slug']) ?>"><?= e((string) $child['name']) ?></a>
<?php render_mega_category_children($child['children'] ?? [], $depth + 1); ?>
</li>
<?php endforeach; ?>
</ul>
<?php
}
}
?>
<?php if ($megaCategories !== []): ?>
<nav class="category-mega-bar" aria-label="Категории товаров">
<div class="category-mega-inner">
<?php foreach ($megaCategories as $category): ?>
<?php if (($category['slug'] ?? '') === 'myasnaya-gastronomiya' || ($category['name'] ?? '') === 'Мясная гастрономия') {
continue;
} ?>
<?php $iconName = category_tree_icon((string) $category['name']); ?>
<div class="mega-item">
<a class="mega-root" href="/catalog/<?= e((string) $category['slug']) ?>">
<span class="mega-category-icon category-icon is-<?= e($iconName) ?>" aria-hidden="true"><?= category_tree_icon_svg($iconName) ?></span>
<span><?= e((string) $category['name']) ?></span>
</a>
<?php render_mega_category_children($category['children'] ?? []); ?>
</div>
<?php endforeach; ?>
</div>
</nav>
<?php endif; ?>