I'm trying to add a CSS class to some tables, based on their HTML-ID, but it's not working.

function mytheme_preprocess_table(&$variables) {
  // Add foo class to tables.
  $variables['attributes']['class'][] = 'foo';

  krumo($variables);
}

Is there any reason why this is not possible? How can this solved?

Comments

cr0ss’s picture

What are the tables you trying to preprocess like this?

If they are rendered by views for example - template_preprocess_table will not work, because view uses own theming function for tables.

hass’s picture

I need to add this to every table in the system. Why should a table in views not use the standard theme functions? That's why we have theme functions, isn't it? :-) I think I tried this on several views tables...

cr0ss’s picture

See sites/all/modules/contrib/views/theme. Though I'm agree this could be useful to have default theme_table as part of views' theming function.

hass’s picture

I give it a try and move the case to views than. Thx

sun’s picture

Category: bug » support
Status: Active » Fixed
hass’s picture

Project: Drupal core » Views (for Drupal 7)
Version: 7.x-dev » 7.x-3.5
Component: theme system » Code
Category: support » bug
Status: Fixed » Active
dawehner’s picture

Status: Active » Closed (won't fix)

Views is not using theme_table, so template_preprocess_table is not working.

Use hook_preprocess_views_view_table instead.

hass’s picture

Version: 7.x-3.5 » 8.x-3.x-dev
Status: Closed (won't fix) » Active
Issue tags: +Needs backport to D7

That's the problem. Views should use the core functions and not complicate things.

dawehner’s picture

I will certainly ignore this issue, sorry.

hass’s picture

That are the reasons why views is not ready for D8 core.

dawehner’s picture

Status: Active » Closed (works as designed)

The world is a place of free oppinions, so feel free to contribute in a constructive way.

hass’s picture

Status: Closed (works as designed) » Active
Issue tags: +VDC

We are required to re-use core API function to make something core worthy. These are written rules.

damiankloip’s picture

You are welcome to write a reviewable patch for this. Otherwise not sure 'We are required' is accurate...

tim.plunkett’s picture

Issue tags: -VDC

Removing tag.

hass’s picture

VDC = Views Drupal Core? This is a blocker

xjm’s picture

Category: bug » feature
Issue tags: +VDC

This is a worthwhile feature request, but it is not a bug, and it is definitely not a blocker.

xjm’s picture

Status: Active » Closed (duplicate)