1<?php 2/** 3 * Copyright (c) 2021. ComboStrap, Inc. and its affiliates. All Rights Reserved. 4 * 5 * This source code is licensed under the GPL license found in the 6 * COPYING file in the root directory of this source tree. 7 * 8 * @license GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html) 9 * @author ComboStrap <support@combostrap.com> 10 * 11 */ 12 13namespace ComboStrap; 14 15 16use dokuwiki\Menu\Item\AbstractItem; 17 18/** 19 * Class MenuItem 20 * * 21 * @package ComboStrap 22 * 23 * To be able to debug, disable the trigger data attribute 24 * The popover will stay on the page 25 */ 26class HistoricalBreadcrumbMenuItem extends AbstractItem 27{ 28 29 30 const RECENT_PAGES_VISITED = "Recent Pages Visited"; 31 32 /** 33 * This unique name should not be in the {@link \action_plugin_combo_historicalbreadcrumb} 34 * to avoid circular reference 35 */ 36 const HISTORICAL_BREADCRUMB_NAME = "historical-breadcrumb"; 37 38 39 /** 40 * 41 * @return string 42 */ 43 public function getLabel() 44 { 45 return self::RECENT_PAGES_VISITED; 46 } 47 48 public function getLinkAttributes($classprefix = 'menuitem ') 49 { 50 51 $linkAttributes = parent::getLinkAttributes($classprefix); 52 $linkAttributes['href'] = "#"; 53 $dataAttributeNamespace = Bootstrap::getDataNamespace(); 54 $linkAttributes["data{$dataAttributeNamespace}-toggle"] = "popover"; 55 $linkAttributes["data{$dataAttributeNamespace}-html"] = "true"; 56 global $lang; 57 $linkAttributes["data{$dataAttributeNamespace}-title"] = $lang['breadcrumb']; 58 59 60 $pages = array_reverse(breadcrumbs()); 61 62 /** 63 * All page should be shown, 64 * also the actual 65 * because when the user is going 66 * in admin mode, it's an easy way to get back 67 */ 68 $actualPageId = array_keys($pages)[0]; 69 $actualPageName = array_shift($pages); 70 $html = $this->createLink($actualPageId,$actualPageName, self::HISTORICAL_BREADCRUMB_NAME ."-home"); 71 72 $html .= '<ol>' . PHP_EOL; 73 foreach ($pages as $id => $name) { 74 75 $html .= '<li>'; 76 $html .= $this->createLink($id,$name); 77 $html .= '</li>' . PHP_EOL; 78 79 } 80 $html .= '</ol>' . PHP_EOL; 81 $html .= '</nav>' . PHP_EOL; 82 $linkAttributes["data{$dataAttributeNamespace}-content"] = $html; 83 84 // Dismiss on next click 85 // To debug, just comment this line 86 $linkAttributes["data{$dataAttributeNamespace}-trigger"] = "focus"; 87 88 // See for the tabindex 89 // https://getbootstrap.com/docs/5.1/components/popovers/#dismiss-on-next-click 90 $linkAttributes['tabindex'] = "0"; 91 92 $linkAttributes["data{$dataAttributeNamespace}custom-class"] = "historical-breadcrumb"; 93 return $linkAttributes; 94 } 95 96 public function getTitle() 97 { 98 /** 99 * The title (unfortunately) is deleted from the anchor 100 * and is used as header in the popover 101 */ 102 return self::RECENT_PAGES_VISITED; 103 } 104 105 public function getSvg() 106 { 107 /** @var string icon file */ 108 return Resources::getImagesDirectory() . '/history.svg'; 109 } 110 111 /** 112 * @param $id 113 * @param $name 114 * @param null $class 115 * @return string 116 */ 117 public function createLink($id,$name,$class=null) 118 { 119 $page = Page::createPageFromId($id); 120 if ($name == "start") { 121 $name = "Home Page"; 122 } else { 123 $name = $page->getTitleNotEmpty(); 124 } 125 $tagAttributes = null; 126 if($class!=null){ 127 $tagAttributes = TagAttributes::createEmpty(); 128 $tagAttributes->addClassName($class); 129 } 130 $link = LinkUtility::createFromPageId($id,$tagAttributes); 131 132 return $link->renderOpenTag() . $name . $link->renderClosingTag(); 133 } 134 135 136} 137