1 | <?php |
||
2 | |||
3 | namespace Elgg\Menus; |
||
4 | |||
5 | use Elgg\Menu\PreparedMenu; |
||
6 | |||
7 | /** |
||
8 | * Prepares breadcrumbs |
||
9 | * |
||
10 | * @since 5.0 |
||
11 | */ |
||
12 | class Breadcrumbs { |
||
13 | |||
14 | /** |
||
15 | * Prepare breadcrumbs before display. This turns titles into 100-character excerpts, and also |
||
16 | * removes the last crumb if it's not a link. |
||
17 | * |
||
18 | * @param \Elgg\Event $event 'prepare', 'menu:breadcrumbs' |
||
19 | * |
||
20 | * @return void |
||
21 | */ |
||
22 | 45 | public static function cleanupBreadcrumbs(\Elgg\Event $event): void { |
|
23 | /* @var $breadcrumbs PreparedMenu */ |
||
24 | 45 | $breadcrumbs = $event->getValue(); |
|
25 | |||
26 | 45 | $items = $breadcrumbs->getItems('default'); |
|
27 | 45 | if (empty($items)) { |
|
28 | 9 | return; |
|
29 | } |
||
30 | |||
31 | 36 | $last = null; |
|
32 | 36 | foreach ($items as $crumb) { |
|
33 | 36 | $last = $crumb; |
|
34 | 36 | $crumb->setText(elgg_get_excerpt((string) $crumb->getText(), 100)); |
|
35 | } |
||
36 | |||
37 | // remove last crumb if it has no link |
||
38 | 36 | if (empty($last->getHref())) { |
|
1 ignored issue
–
show
|
|||
39 | 1 | elgg_log("Having a breadcrumb at the end of the list without a link makes no sense. Please update your code for the '{$last->getText()}[{$last->getID()}]' breadcrumb.", 'NOTICE'); |
|
40 | 1 | $breadcrumbs->getSection('default')->remove($last->getID()); |
|
41 | 35 | } elseif (!$last->getChildren() && elgg_http_url_is_identical(elgg_get_current_url(), $last->getHref())) { |
|
42 | elgg_log("Having a breadcrumb at the end of the list which links to the current page makes no sense. Please update your code for the '{$last->getText()}[{$last->getID()}]' breadcrumb.", 'NOTICE'); |
||
43 | $breadcrumbs->getSection('default')->remove($last->getID()); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Adds a home item |
||
49 | * |
||
50 | * @param \Elgg\Event $event 'prepare', 'menu:breadcrumbs' |
||
51 | * |
||
52 | * @return null|PreparedMenu |
||
53 | */ |
||
54 | 43 | public static function addHomeItem(\Elgg\Event $event): ?PreparedMenu { |
|
55 | /* @var $return PreparedMenu */ |
||
56 | 43 | $return = $event->getValue(); |
|
57 | |||
58 | /* @var $items \ElggMenuItem[] */ |
||
59 | 43 | $items = $return->getItems('default'); |
|
60 | 43 | if (empty($items)) { |
|
61 | 9 | return null; |
|
62 | } |
||
63 | |||
64 | 34 | $href = elgg_get_site_url(); |
|
65 | 34 | if (elgg_in_context('admin')) { |
|
66 | $href = elgg_generate_url('admin'); |
||
67 | } |
||
68 | |||
69 | 34 | array_unshift($items, \ElggMenuItem::factory([ |
|
70 | 34 | 'name' => 'home', |
|
71 | 34 | 'icon' => 'home', |
|
72 | 34 | 'text' => false, |
|
73 | 34 | 'title' => elgg_get_site_entity()->getDisplayName(), |
|
74 | 34 | 'href' => $href, |
|
75 | 34 | ])); |
|
76 | |||
77 | 34 | $return->getSection('default')->fill($items); |
|
78 | |||
79 | 34 | return $return; |
|
80 | } |
||
81 | } |
||
82 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.