54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Jinove\Vinoteca;
|
|
|
|
use Bitrix\Main\Localization\Loc;
|
|
|
|
Loc::loadMessages(__FILE__);
|
|
|
|
class Breadcrumbs
|
|
{
|
|
public static function show(array $items): void
|
|
{
|
|
global $APPLICATION;
|
|
|
|
$APPLICATION->AddChainItem((string)Loc::getMessage("VINO_BREADCRUMBS_HOME"), SITE_DIR);
|
|
foreach ($items as $item) {
|
|
$link = (string)($item[1] ?? "");
|
|
if ($link !== "" && str_starts_with($link, "/") && !str_starts_with($link, SITE_DIR)) {
|
|
$link = SITE_DIR . ltrim($link, "/");
|
|
}
|
|
$APPLICATION->AddChainItem((string)$item[0], $link);
|
|
}
|
|
$APPLICATION->IncludeComponent("bitrix:breadcrumb", "vinoteca", [
|
|
"START_FROM" => "0",
|
|
"PATH" => "",
|
|
"SITE_ID" => SITE_ID,
|
|
], false, ["HIDE_ICONS" => "Y"]);
|
|
}
|
|
|
|
public static function schema(array $chain, string $self): array
|
|
{
|
|
$last = count($chain) - 1;
|
|
$items = [];
|
|
foreach ($chain as $i => $item) {
|
|
$link = (string)$item["LINK"];
|
|
$items[] = [
|
|
"@type" => "ListItem",
|
|
"position" => $i + 1,
|
|
"name" => $item["TITLE"],
|
|
"item" => $i < $last && $link !== "" ? Config::host() . $link : $self,
|
|
];
|
|
}
|
|
|
|
return [
|
|
"@context" => "https://schema.org",
|
|
"@type" => "BreadcrumbList",
|
|
"@id" => $self . "#breadcrumb",
|
|
"itemListElement" => $items,
|
|
];
|
|
}
|
|
}
|