getType(); /** * Print in function of the depth */ switch ($type) { case self::NAVIGATION_TYPE: /** * https://www.w3.org/TR/wai-aria-practices/examples/breadcrumb/index.html * Arial-label Provides a label that describes the type of navigation provided in the nav element. */ $tagAttributes->addOutputAttributeValue("aria-label", "Hierarchical breadcrumb"); $htmlOutput = $tagAttributes->toHtmlEnterTag("nav"); $htmlOutput .= ''; $htmlOutput .= ''; return $htmlOutput; case self::TYPOGRAPHY_TYPE: try { $requiredDepth = DataType::toInteger($tagAttributes->getValueAndRemoveIfPresent(self::DEPTH_ATTRIBUTE)); } catch (ExceptionBadArgument $e) { LogUtility::error("We were unable to determine the depth attribute. The depth was set to 1. Error: {$e->getMessage()}"); $requiredDepth = 1; } if ($requiredDepth > 1) { SnippetSystem::getFromContext()->attachCssInternalStyleSheet("breadcrumb-$type"); } $htmlOutput = $tagAttributes->toHtmlEnterTag("span"); $lisHtmlOutput = ""; $actualDepth = 0; while (true) { try { $actualPath = $actualPath->getParent(); } catch (ExceptionNotFound $e) { break; } $actualDepth = $actualDepth + 1; $nameOrDefault = $actualPath->getNameOrDefault(); $liHtmlOutput = "$nameOrDefault"; $lisHtmlOutput = $liHtmlOutput . $lisHtmlOutput; if ($actualDepth >= $requiredDepth) { break; } } $htmlOutput .= $lisHtmlOutput; $htmlOutput .= ''; return $htmlOutput; default: // internal error LogUtility::error("The breadcrumb type ($type) is unknown"); return ""; } } /** * @param MarkupPath $page * @param bool $current * @param bool $link * @return string - the list item for the page */ public static function getLiHtmlOutput(MarkupPath $page, bool $current = false, bool $link = true): string { $liClass = ""; $liArial = ""; if ($current) { $liClass = " active"; /** * https://www.w3.org/WAI/ARIA/apg/patterns/breadcrumb/ * Applied to a link in the breadcrumb set to indicate that it represents the current page. */ $liArial = " aria-current=\"page\""; } $liHtmlOutput = "
  • "; if (FileSystems::exists($page->getPathObject()) && $current === false) { if ($link) { $liHtmlOutput .= $page->getHtmlAnchorLink(self::CANONICAL_HIERARCHICAL); } else { $liHtmlOutput .= $page->getNameOrDefault(); } } else { $liHtmlOutput .= $page->getNameOrDefault(); } $liHtmlOutput .= '
  • '; return $liHtmlOutput; } /** * Same rendering for typographic or navigational breadcrumb * @param TagAttributes $tagAttributes * @return string */ public static function render(TagAttributes $tagAttributes): string { try { ExecutionContext::getActualOrCreateFromEnv() ->getExecutingMarkupHandler() ->getOutputCacheDependencies() // the output has the data from the requested page ->addDependency(MarkupCacheDependencies::REQUESTED_PAGE_DEPENDENCY) // the data from the requested page is dependent on the name, title or description of the page ->addDependency(MarkupCacheDependencies::PAGE_PRIMARY_META_DEPENDENCY); } catch (ExceptionNotFound $e) { // not a fetcher markup run } return BreadcrumbTag::toBreadCrumbHtml($tagAttributes); } public static function getDefaultBlockAttributes(): array { return [TagAttributes::TYPE_KEY => BreadcrumbTag::NAVIGATION_TYPE]; } public static function handleEnter(TagAttributes $tagAttributes): array { if ($tagAttributes->getType() === self::TYPOGRAPHY_TYPE) { return [PluginUtility::DISPLAY => Call::INLINE_DISPLAY]; } else { return [PluginUtility::DISPLAY => Call::BlOCK_DISPLAY]; } } }