Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

theme_item_list()'s $items variable has been changed to only accept either a plain string as item, or a render array.

The behavior for string values is unchanged. This change only affects code that

  • specifies custom attributes for the list item. (not the content within)
  • renders nested/child lists.

Drupal 7

$items = array();
// A simple string item (unchanged).
$items[] = 'Simple string';

// Set custom attributes for a list item.
$items[] = array(
  'data' => 'Custom item',
  'class' => array('custom-item-class'),
);

// Add an item with a nested/child list.
$items[] = array(
  'data' => 'Parent item',
  'children' => array(
    'Simple string child',
    array(
      'data' => 'Second child item with custom attributes',
      'class' => array('custom-child-item-class'),
    ),
  ),
);

$output = theme('item_list', array('items' => $items));

Drupal 8

$items = [];
// A simple string item (unchanged).
$items[] = 'Simple string';

// A simple string item as render array (new, same effect/output as previous).
$items[] = [
  '#markup' => 'Simple string',
];

// Set custom attributes for a list item.
$items[] = [
  '#markup' => 'Custom item',
  '#wrapper_attributes' => [
    'class' => ['custom-item-class'],
  ],
];

// Add an item with a nested/child list.
$items[] = [
  '#markup' => 'Parent item',
  'children' => [
    'Simple string child',
    [
      '#markup' => 'Second child item with custom attributes',
      '#wrapper_attributes' => [
        'class' => ['custom-child-item-class'],
      ],
    ],
  ],
];

$output = theme('item_list', ['items' => $items]);

A list item and also a nested/child list item can be any kind of render array.

Note that render array attributes for nested/child lists are automatically inherited and do not have to be specified manually — i.e., as in Drupal 7, nested child lists automatically use the same theme_item_list() properties and attributes, unless explicitly overridden.

Impacts: 
Module developers
Themers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

phponwebsites’s picture

I tried to use theme() in theme_preprocess_page but it gives Fatal error: Call to undefined function theme().
This is my code:

   $items = array(
    array('#markup' => 'galip_social'),
    array('#markup' => 'galip_social'),
    array('#markup' => 'galip_social'),
    array('#markup' => 'galip_social'),
    array('#markup' => 'galip_social'),
  );
  $list = theme('item_list', array('items' => $items));
rpsu’s picture

See other Change records for more info: https://www.drupal.org/node/2195739

--
Perttu Ehn