This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HtmlListFormatter.php
70 lines (62 loc) · 1.99 KB
/
HtmlListFormatter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* The WordCrumbs HtmlListFormatter class
*
* @author bjoluc <25661029+bjoluc@users.noreply.github.com>
* @version 1.0.0
*
* @license GPL-3.0-or-later
*/
namespace bjoluc\WordCrumbs\Formatters;
/**
* A Formatter that produces an HTML list whose entries are breadcrumb names,
* wrapped in <a> tags. If a breadcrumb is marked as active or does not have an
* url, <span> is used instead of <a>.
*
* @since 1.0.0
*/
class HtmlListFormatter extends HtmlFormatter
{
protected $_listClasses;
protected $_listEntryClasses;
/**
* Initialize a new HtmlListFormatter.
*
* @param string[] $anchorClasses (optional) An array of css classes that
* are added to the HTML anchor (or span) tags that wrap breadcrumbs
* @param string[] $listClasses (optional) An array of css classes that are
* added to the wrapping <li> element
* @param string[] $listEntryClasses (optional) An array of css classes that
* are added to the <li> tags that wrap breadcrumbs
*/
public function __construct($anchorClasses = [], $listClasses = [], $listEntryClasses = [])
{
parent::__construct('', $anchorClasses);
$this->_listClasses = implode(' ', $listClasses);
$this->_listEntryClasses = implode(' ', $listEntryClasses);
}
public function getPre()
{
$tag = '<ul';
if ($this->_listClasses !== '') {
$tag .= ' class="' . $this->_listClasses . '"';
}
return $tag . '>';
}
public function getPost()
{
return '</ul>';
}
public function getPreBreadcrumb($breadcrumb, $isLast)
{
$tag = '<li';
if ($this->_listEntryClasses !== '') {
$tag .= ' class="' . $this->_listEntryClasses . '"';
}
return $tag . '>' . parent::getPreBreadcrumb($breadcrumb, $isLast);
}
public function getPostBreadcrumb($breadcrumb, $isLast)
{
return parent::getPostBreadcrumb($breadcrumb, $isLast) . '</li>';
}
}