1<?php
2/**
3 * View a item to use in a list
4 *
5 * @uses $vars['item']       ElggEntity, ElggAnnotation, ElggRiverItem or ElggRelationship object
6 * @uses $vars['item_class'] Additional CSS class for the <li> elements
7 * @uses $vars['content']    Content of the list item
8 */
9
10$content = elgg_extract('content', $vars);
11$item = elgg_extract('item', $vars);
12
13$li_attrs = [
14	'class' => elgg_extract_class($vars, 'elgg-item', 'item_class'),
15];
16
17if ($item instanceof \ElggEntity) {
18	$guid = $item->guid;
19	$type = $item->type;
20	$subtype = $item->getSubtype();
21
22	$li_attrs['id'] = "elgg-$type-$guid";
23
24	$li_attrs['class'][] = "elgg-item-$type";
25	if ($subtype) {
26		$li_attrs['class'][] = "elgg-item-$type-$subtype";
27	}
28} elseif ($item instanceof \ElggRiverItem) {
29	$type = $item->getType();
30
31	$li_attrs['id'] = "item-$type-{$item->id}";
32
33	$li_attrs['class'][] = "elgg-item-$type";
34
35	$object = $item->getObjectEntity();
36	if ($object instanceof \ElggEntity) {
37		$li_attrs['class'][] = "elgg-item-{$type}-{$object->getType()}-{$object->getSubtype()}-{$item->action_type}";
38	}
39} elseif ($item instanceof ElggRelationship) {
40	$type = $item->getType();
41	$relationship = $item->getSubtype();
42	$id = $item->id;
43
44	$li_attrs['id'] = "elgg-{$type}-{$id}";
45
46	$li_attrs['class'][] = "elgg-item-{$type}";
47	$li_attrs['class'][] = "elgg-item-{$type}-{$relationship}";
48} elseif (is_callable([$item, 'getType'])) {
49	$type = $item->getType();
50
51	$li_attrs['id'] = "item-$type-{$item->id}";
52}
53
54echo elgg_format_element('li', $li_attrs, $content);
55