Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By sun on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
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
Comments
Fatal error: Call to undefined function theme()
I tried to use theme() in theme_preprocess_page but it gives Fatal error: Call to undefined function theme().
This is my code:
http://www.phponwebsites.com/
Using theme() is deprecated
See other Change records for more info: https://www.drupal.org/node/2195739
--
Perttu Ehn