root / drupal7 / sites / all / themes / bootstrap / templates / system / item-list.func.php @ 749b8a23
1 | caf16a48 | Assos Assos | <?php
|
---|---|---|---|
2 | /**
|
||
3 | * @file
|
||
4 | * Stub file for bootstrap_item_list().
|
||
5 | */
|
||
6 | |||
7 | /**
|
||
8 | * Returns HTML for a list or nested list of items.
|
||
9 | *
|
||
10 | * - Uses an early D8 version of the theme function, which fixes bugs (and was
|
||
11 | * refused for commit because it was "too late to change theme output)".
|
||
12 | * - Removes first/last, even/odd classes.
|
||
13 | * - Removes useless div.item-list wrapper, allows optional #wrapper_attributes.
|
||
14 | * - Removes hard-coded #title as <h3>, introduce support for #title as an array
|
||
15 | * containing, text, tag and optional attributes.
|
||
16 | *
|
||
17 | * @param array $variables
|
||
18 | * An associative array containing:
|
||
19 | * - items: An array of items to be displayed in the list. If an item is a
|
||
20 | * string, then it is used as is. If an item is an array, then the "data"
|
||
21 | * element of the array is used as the contents of the list item. If an item
|
||
22 | * is an array with a "children" element, those children are displayed in a
|
||
23 | * nested list. All other elements are treated as attributes of the list
|
||
24 | * item element.
|
||
25 | * - title: The title of the list.
|
||
26 | * - type: The type of list to return (e.g. "ul", "ol").
|
||
27 | * - attributes: The attributes applied to the list element.
|
||
28 | *
|
||
29 | * @return string
|
||
30 | * The constructed HTML.
|
||
31 | *
|
||
32 | * @see theme_item_list()
|
||
33 | *
|
||
34 | * @ingroup theme_functions
|
||
35 | */
|
||
36 | function bootstrap_item_list($variables) { |
||
37 | $items = $variables['items']; |
||
38 | $title = $variables['title']; |
||
39 | $type = $variables['type']; |
||
40 | $list_attributes = $variables['attributes']; |
||
41 | |||
42 | // Drupal core only supports #title as a string. This implementation supports
|
||
43 | // heading level, and attributes as well.
|
||
44 | $heading = ''; |
||
45 | if (!empty($title)) { |
||
46 | // If it's a string, normalize into an array.
|
||
47 | if (is_string($title)) { |
||
48 | $title = array( |
||
49 | 'text' => $title, |
||
50 | ); |
||
51 | } |
||
52 | // Set defaults.
|
||
53 | $title += array( |
||
54 | 'level' => 'h3', |
||
55 | 'attributes' => array(), |
||
56 | ); |
||
57 | // Heading outputs only when it has text.
|
||
58 | if (!empty($title['text'])) { |
||
59 | $heading .= '<' . $title['level'] . drupal_attributes($title['attributes']) . '>'; |
||
60 | $heading .= empty($title['html']) ? check_plain($title['text']) : $title['text']; |
||
61 | $heading .= '</' . $title['level'] . '>'; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | $output = ''; |
||
66 | if ($items) { |
||
67 | $output .= '<' . $type . drupal_attributes($list_attributes) . '>'; |
||
68 | foreach ($items as $key => $item) { |
||
69 | $attributes = array(); |
||
70 | |||
71 | if (is_array($item)) { |
||
72 | $value = ''; |
||
73 | if (isset($item['data'])) { |
||
74 | // Allow data to be renderable.
|
||
75 | if (is_array($item['data']) && (!empty($item['data']['#type']) || !empty($item['data']['#theme']))) { |
||
76 | $value .= drupal_render($item['data']); |
||
77 | } |
||
78 | else {
|
||
79 | $value .= $item['data']; |
||
80 | } |
||
81 | } |
||
82 | $attributes = array_diff_key($item, array('data' => 0, 'children' => 0)); |
||
83 | |||
84 | // Append nested child list, if any.
|
||
85 | if (isset($item['children'])) { |
||
86 | // HTML attributes for the outer list are defined in the 'attributes'
|
||
87 | // theme variable, but not inherited by children. For nested lists,
|
||
88 | // all non-numeric keys in 'children' are used as list attributes.
|
||
89 | $child_list_attributes = array(); |
||
90 | foreach ($item['children'] as $child_key => $child_item) { |
||
91 | if (is_string($child_key)) { |
||
92 | $child_list_attributes[$child_key] = $child_item; |
||
93 | unset($item['children'][$child_key]); |
||
94 | } |
||
95 | } |
||
96 | $value .= theme('item_list', array( |
||
97 | 'items' => $item['children'], |
||
98 | 'type' => $type, |
||
99 | 'attributes' => $child_list_attributes, |
||
100 | )); |
||
101 | } |
||
102 | } |
||
103 | else {
|
||
104 | $value = $item; |
||
105 | } |
||
106 | |||
107 | $output .= '<li' . drupal_attributes($attributes) . '>' . $value . "</li>\n"; |
||
108 | } |
||
109 | $output .= "</$type>"; |
||
110 | } |
||
111 | |||
112 | // Output the list and title only if there are any list items.
|
||
113 | if (!empty($output)) { |
||
114 | $output = $heading . $output; |
||
115 | } |
||
116 | |||
117 | return $output; |
||
118 | } |