The current theme_item_list has the following arguments: $items, $title, $type
Unfortunally this does not allow us to attribute extra CSS to the list itself.
Example: I need in several cases to add some CSS that indicates the 'active' item in that list, which result in the following

<ul>
<li>1</li>
<li class="active">2</li>
<li>3</li>
</ul>

So, the first option is by adding a new parameter to theme_item_list called $activeindex or such.
The other option is think about a way that allow extra css to be passed. For example, add a $items_css array that could be used to pass extra data to the function and then developers could theme the list as they wish.

What do you think?

CommentFileSizeAuthor
#4 item_list_2.patch.txt1.39 KBCrell
#3 item_list.patch.txt1.34 KBCrell
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Crell’s picture

Assigned: Unassigned » Crell
Status: Active » Postponed

The more standard way, I'd think, would be to allow each element of the $items array to be itself an array of data and attributes, similar to how the theme_table works. I'm not sure what the performance impact of that would be, though. It's definitely a feature change, so won't happen in 4.7.

I'm assigning this to me and setting to postponed, so that I remember it. I've a couple of issues set that way that I plan to come back to after HEAD opens up again. :-) (If anyone else has a better way to do it than that, please feel free to suggest it and/or steal the issue from me.)

Crell’s picture

Version: 4.6.5 » x.y.z

Forgot to change the version. Oops.

Crell’s picture

Status: Postponed » Needs review
FileSize
1.34 KB

And here's a patch that does as I suggest. It makes list items behave like table cells, vis, they can be either a string or an array representing both the content and additional attributes to add (such as classes and ids).

I did some quick benchmarking (hitting devel's clear cache repeatedly both with and without this change and averaging the reported execution time), and the performance difference was about 1.4%. I suspect with caching it will be even less.

Crell’s picture

FileSize
1.39 KB

Keeping up with HEAD. magico, are you still interested? :-)

magico’s picture

I'm still using v4.6. In fact I don't know when I will use v4.7 :-P

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

makes sense. didn't break anything.

drumm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)
seanberto’s picture

Version: x.y.z » 4.7.4
Status: Closed (fixed) » Active

Does this patch work with 4.7.4? I'm trying to add the sticky CSS attribute when using list and table views. I tried to apply the patch, but it broke my item listing in a view.

Thanks,
sean

Crell’s picture

Status: Active » Closed (fixed)

It may, although you may need to apply it manually (copy and paste code) since the offsets are probably all wrong by this point. I'm not planning on backporting it myself, though, so best of luck with it. :-)

And please don't reopen closed issues. Thanks.