theme_item_list()/item-list.html.twig is broken when "items" variable is an associative array (followup for tests)

Created on 11 October 2012, almost 13 years ago
Updated 12 June 2025, about 2 months ago

If I do

$variables = array(
  'items' => array(
    'Item one',
    'Item two',
    'Item three',
  ),
);

print theme('item_list', $variables);

$variables = array(
  'items' => array(
    'one' => 'Item one',
    'two' => 'Item two',
    'three' => 'Item three',
  ),
);

print theme('item_list', $variables);

The result will be:

<div class="item-list">
  <ul>
    <li class="first">Item one</li>
    <li>Item two</li>
    <li class="last">Item three</li>
  </ul>
</div>

<div class="item-list">
  <ul>
    <li class="first">Item one</li>
    <li class="first">Item two</li>
    <li class="first">Item three</li>
  </ul>
</div>

When using associative arrays, every item has the "first" class, and the "last" class is missing on the last one.

The documentation says nothing about associative arrays on the items parameter, so I think this is a bug that must be fixed. Otherwise we must fix the docs to clarify that only indexed arrays are allowed.

PS: I think this issue doesn't affect Drupal 8 due to the refactorings done at #256827: Various bugs in theme_item_list() β†’

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

theme system

Created by

πŸ‡§πŸ‡·Brazil danillonunes

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024