diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 8d527df..6b4f40d 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2294,20 +2294,38 @@ function theme_mark($variables) { } /** - * Preprocesses variables for theme_item_list(). + * Preprocesses variables for item list templates. + * + * Default template: item-list.html.twig. * * @param array $variables - * An associative array containing theme variables for theme_item_list(). - * 'items' in variables will be processed to automatically inherit the - * variables of this list to any possibly contained nested lists that do not - * specify custom render properties. This allows callers to specify larger - * nested lists, without having to explicitly specify and repeat the render - * properties for all nested child lists. + * An associative array containing: + * - 'items' in variables will be processed to automatically inherit the + * variables of this list to any possibly contained nested lists that do + * not specify custom render properties. This allows callers to specify + * larger nested lists, without having to explicitly specify and repeat the + * render properties for all nested child lists. + * - title: A title to be prepended to the list. + * - type: The type of list to return (e.g. "ul", "ol"). */ function template_preprocess_item_list(&$variables) { + $variables['title'] = (string) $variables['title']; + // Change the name since 'type' clashes with #type. + $variables['tag'] = $variables['type']; + + // Prepare for adding classes to each item. + $num_items = count($variables['items']); + $i = 0; + + debug($variables['items']); foreach ($variables['items'] as &$item) { + $i++; + $attributes = array(); // If the item value is an array, then it is a render array. if (is_array($item)) { + if (isset($item['#wrapper_attributes']) && is_array($item['#wrapper_attributes'])) { + $attributes += $item['#wrapper_attributes']; + } // Determine whether there are any child elements in the item that are not // fully-specified render arrays. If there are any, then the child // elements present nested lists and we automatically inherit the render @@ -2337,66 +2355,23 @@ function template_preprocess_item_list(&$variables) { } } } - } -} - -/** - * Returns HTML for a list or nested list of items. - * - * @param $variables - * An associative array containing: - * - items: A list of items to render. Allowed values are strings or - * render arrays. Render arrays can specify list item attributes in the - * #wrapper_attributes property. - * - title: The title of the list. - * - type: The type of list to return (e.g. "ul", "ol"). - * - attributes: The attributes applied to the list element. - */ -function theme_item_list($variables) { - $items = $variables['items']; - $title = (string) $variables['title']; - // @todo 'type' clashes with '#type'. Rename to 'tag'. - $type = $variables['type']; - $list_attributes = $variables['attributes']; - - $output = ''; - if ($items) { - $output .= '<' . $type . new Attribute($list_attributes) . '>'; - - $num_items = count($items); - $i = 0; - foreach ($items as &$item) { - $i++; - $attributes = array(); - if (is_array($item)) { - if (isset($item['#wrapper_attributes'])) { - $attributes = $item['#wrapper_attributes']; - } - $item = drupal_render($item); - } - $attributes['class'][] = ($i % 2 ? 'odd' : 'even'); - if ($i == 1) { - $attributes['class'][] = 'first'; - } - if ($i == $num_items) { - $attributes['class'][] = 'last'; - } - $output .= '