-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbreadcrumbs.php
More file actions
109 lines (94 loc) · 2.33 KB
/
Copy pathbreadcrumbs.php
File metadata and controls
109 lines (94 loc) · 2.33 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php namespace Feather\Components\Support;
use URL;
use HTML;
use Feather\Core;
use Feather\Components\Foundation\Component;
class Breadcrumbs extends Component {
/**
* Crumbs to be dropped on the trail.
*
* @var array
*/
public $crumbs = array();
/**
* Drop a crumb.
*
* @param array|object $crumb
* @return Feather\Components\Support\Breadcrumbs
*/
public function drop($crumb)
{
if($crumb instanceof Core\Place)
{
$this->place($crumb);
}
else
{
// If the crumb is an object, such as a Laravel Messages object, then convert it
// to a string as any objects being passed to this method will have a __toString()
if(is_object($crumb))
{
$crumb = array((string) $crumb);
}
elseif(!is_array($crumb))
{
$crumb = array($crumb);
}
// Fetch the title of the crumb and the crumbs link. If the crumb does not have
// a supplied link then use the current page.
$title = isset($crumb['title']) ? $crumb['title'] : array_shift($crumb);
$link = isset($crumb['link']) ? $crumb['link'] : URL::current();
$this->crumbs[] = (object) compact('link', 'title');
}
return $this;
}
/**
* Leaves a trail of crumbs.
*
* @return string
*/
public function trail($element = 'li')
{
$response = array(
$this->item(URL::to_route('feather'), $this->feather['config']->get('feather: db.forum.title'), $element)
);
foreach($this->crumbs as $crumb)
{
$response[] = $this->item($crumb->link, $crumb->title, $element);
}
return implode(PHP_EOL, $response);
}
/**
* Adds a place to the trail.
*
* @param Feather\Core\Place $place
* @return array
*/
protected function place($place)
{
// Add each of the ancestors of this place to the crumbs.
foreach($place->crumbs() as $crumb)
{
$this->crumbs[] = (object) array(
'link' => URL::to_route('place', array($crumb->id, $crumb->slug)),
'title' => $crumb->name
);
}
return $this->crumbs[] = (object) array(
'link' => URL::to_route('place', array($place->id, $place->slug)),
'title' => $place->name
);
}
/**
* Return a list item with the link.
*
* @param string $link
* @param string $text
* @param string $element
* @return string
*/
public function item($link, $text, $element = 'li')
{
return "<{$element}>" . HTML::link($link, $text) . "</{$element}>";
}
}