1818use \App \Base \Traits \AdminTrait ;
1919use \App \Site \Controllers \Frontend \Page ;
2020use \App \Site \Models \Rewrite ;
21+ use \Degami \Basics \Html \TagElement ;
2122
2223/**
2324 * Breadcrumbs Block
@@ -44,54 +45,96 @@ public function renderHTML(BasePage $current_page = null)
4445 $ menu_item = reset ($ menuitems );
4546 $ home_url = $ this ->getRouting ()->getUrl ('frontend.root ' );
4647
47- $ breadcrumbs_links = [];
48+ $ breadcrumbs_links = $ this ->getContainer ()->make (TagElement::class, ['options ' => [
49+ 'tag ' => 'ol ' ,
50+ 'attributes ' => [
51+ 'class ' => 'breadcrumb ' ,
52+ ],
53+ ]]);
54+
4855
4956 $ homepageid = $ this ->getSiteData ()->getHomePageId (
5057 $ this ->getSiteData ()->getCurrentWebsiteId (),
5158 $ current_page ->getCurrentLocale ()
5259 );
5360
5461 if (!$ current_page ->isHomePage ()) {
55- $ breadcrumbs_links [] = '<a href=" ' .$ home_url .'"> ' .$ this ->getUtils ()->translate ('Home ' , $ locale ).'</a> ' ;
62+ $ li = $ this ->getContainer ()->make (
63+ TagElement::class,
64+ ['options ' => [
65+ 'tag ' => 'li ' ,
66+ 'attributes ' => ['class ' => 'breadcrumb-item ' ],
67+ ]]
68+ );
69+
70+ $ atag = $ this ->getContainer ()->make (
71+ TagElement::class,
72+ ['options ' => [
73+ 'tag ' => 'a ' ,
74+ 'attributes ' => [
75+ 'class ' => 'breadcrumb-link ' ,
76+ 'href ' => $ home_url ,
77+ 'title ' => (trim ($ title ) != '' ) ? $ this ->getUtils ()->translate ($ title , $ this ->getCurrentLocale ()) : '' ,
78+ ],
79+ 'text ' => $ this ->getUtils ()->translate ('Home ' , $ locale ),
80+ ]]
81+ );
82+
83+ $ li ->addChild ($ atag );
84+ $ breadcrumbs_links ->addChild ($ li );
5685 }
5786
58- $ breadcrumbs_html = '<nav aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"> ' ;
5987 if ($ menu_item instanceof Menu) {
6088 $ breadcrumbs = explode ('/ ' , $ menu_item ->getBreadcrumb ());
6189 if (count ($ breadcrumbs ) == 0 || $ breadcrumbs [count ($ breadcrumbs )-1 ] != $ menu_item ->getId ()) {
6290 $ breadcrumbs [] = $ menu_item ->getId ();
6391 }
6492
65- array_push (
66- $ breadcrumbs_links ,
67- ...array_map (
68- function ($ id ) use ($ homepageid , $ locale ) {
69- $ menuItem = $ this ->getContainer ()->call ([Menu::class, 'load ' ], ['id ' => $ id ]);
70-
71- if ($ menuItem ->getRewriteId ()) {
72- /**
73- * @var Rewrite $rewrite
74- */
75- $ rewrite = $ this ->getContainer ()->make (Rewrite::class)->fill ($ menuItem ->getRewriteId ());
76- if ($ rewrite ->getRoute () == '/page/ ' .$ homepageid ) {
77- $ menuItem ->setTitle ($ this ->getUtils ()->translate ('Home ' , $ locale ));
78- }
93+ foreach (array_map (
94+ function ($ id ) use ($ homepageid , $ locale ) {
95+ $ menuItem = $ this ->getContainer ()->call ([Menu::class, 'load ' ], ['id ' => $ id ]);
96+
97+ if ($ menuItem ->getRewriteId ()) {
98+ /**
99+ * @var Rewrite $rewrite
100+ */
101+ $ rewrite = $ this ->getContainer ()->make (Rewrite::class)->fill ($ menuItem ->getRewriteId ());
102+ if ($ rewrite ->getRoute () == '/page/ ' .$ homepageid ) {
103+ $ menuItem ->setTitle ($ this ->getUtils ()->translate ('Home ' , $ locale ));
79104 }
105+ }
80106
81- $ leaf = [
82- 'title ' => $ menuItem ->getTitle (),
83- 'href ' => $ menuItem ->getLinkUrl (),
84- 'target ' => $ menuItem ->getTarget (),
85- ];
86- return $ this ->_renderLink ($ leaf );
87- },
88- array_filter ($ breadcrumbs )
89- )
90- );
107+ $ leaf = [
108+ 'title ' => $ menuItem ->getTitle (),
109+ 'href ' => $ menuItem ->getLinkUrl (),
110+ 'target ' => $ menuItem ->getTarget (),
111+ ];
112+ return $ this ->_renderLink ($ leaf );
113+ },
114+ array_filter ($ breadcrumbs )
115+ ) as $ atag ) {
116+ $ li = $ this ->getContainer ()->make (
117+ TagElement::class,
118+ ['options ' => [
119+ 'tag ' => 'li ' ,
120+ 'attributes ' => ['class ' => 'breadcrumb-item ' ],
121+ ]]
122+ );
123+
124+ $ li ->addChild ($ atag );
125+ $ breadcrumbs_links ->addChild ($ li );
126+ }
91127 }
92- $ breadcrumbs_html .= implode ('</li><li class="breadcrumb-item"> ' , $ breadcrumbs_links );
93- $ breadcrumbs_html .= '</li></ol></nav> ' ;
94- return $ breadcrumbs_html ;
128+
129+ $ breadcrumbs_container = $ this ->getContainer ()->make (TagElement::class, ['options ' => [
130+ 'tag ' => 'nav ' ,
131+ 'attributes ' => [
132+ 'aria-label ' => 'breadcrumb ' ,
133+ ],
134+ ]]);
135+
136+ $ breadcrumbs_container ->addChild ($ breadcrumbs_links );
137+ return $ breadcrumbs_container ;
95138 }
96139
97140 /**
@@ -103,6 +146,20 @@ function ($id) use ($homepageid, $locale) {
103146 */
104147 protected function _renderLink ($ leaf , $ link_class = 'breadcrumb-link ' )
105148 {
106- return '<a class=" ' .$ link_class .'" href=" ' .$ leaf ['href ' ].'" ' . (($ leaf ['target ' ]) ? ' target=" ' .$ leaf ['target ' ].'" ' :'' ) .'> ' .$ leaf ['title ' ].'</a> ' ;
149+ $ link_options = [
150+ 'tag ' => 'a ' ,
151+ 'attributes ' => [
152+ 'class ' => $ link_class ,
153+ 'href ' => $ leaf ['href ' ],
154+ 'title ' => $ leaf ['title ' ],
155+ ],
156+ 'text ' => $ leaf ['title ' ],
157+ ];
158+
159+ if ($ leaf ['target ' ]) {
160+ $ link_options ['attributes ' ]['target ' ] = $ leaf ['target ' ];
161+ }
162+
163+ return $ this ->getContainer ()->make (TagElement::class, ['options ' => $ link_options ]);
107164 }
108165}
0 commit comments