Hi, I'm getting undefined indexes for theme_table. See below.
As documented, this is a great function. It just needs to do a little type checking before using the variables. See the top of the function. Otherwise, all these features, even if not used, need to be defined in every function call - making this function much less useful.
function theme_table($variables) {
$header = $variables['header'];
$rows = $variables['rows'];
$attributes = $variables['attributes'];
$caption = $variables['caption'];
$colgroups = $variables['colgroups'];
$sticky = $variables['sticky'];
$empty = $variables['empty'];
...
}
...
$html = theme_table( array( 'header'=>$header, 'rows'=>$rows) );
Causes:
# Notice: Undefined index: attributes in theme_table() (line 1618 of /home/quickstart/websites/test3.dev/includes/theme.inc).
# Notice: Undefined index: caption in theme_table() (line 1619 of /home/quickstart/websites/test3.dev/includes/theme.inc).
# Notice: Undefined index: colgroups in theme_table() (line 1620 of /home/quickstart/websites/test3.dev/includes/theme.inc).
# Notice: Undefined index: sticky in theme_table() (line 1621 of /home/quickstart/websites/test3.dev/includes/theme.inc).
# Notice: Undefined index: empty in theme_table() (line 1622 of /home/quickstart/websites/test3.dev/includes/theme.inc).
Comments
Comment #1
droplet commented#1001990: theme_* functions use associative arrays with optional indexes, but use values without checking
Comment #2
MichaelCole commentedThe linked bug only deals with theme_link. This is about theme_table. I made a patch, so let's deal with it here.
This patch creates appropriate HTML for the following cases: header+rows, header only, rows only, none.
Example uses:
Comment #4
MichaelCole commentedSame effect, better syntax for sticky.
Comment #5
MichaelCole commented#2: theme_table.patch queued for re-testing.
Comment #7
MichaelCole commentedHow about a patch from the root :-)
Comment #8
bellHead commentedIt would really make the committer's lives easier if this and #1001990: theme_* functions use associative arrays with optional indexes, but use values without checking were merged - and the other affected functions added to the patch.
Since you seem opposed to the idea of this issue being closed as duplicate should I just merge the patch from #1001990 in with the one here and extend it to cover the other affected functions?
Comment #9
MichaelCole commentedHi bellHead, I'm not that opposed to it.
1) I'd already written the patch
2) I wanted to contribute to core :-)
This issue doesn't need to happen alone though. Whatever works best for everybody works for me.
Are there other functions I could help fix? It seemed like theme_link and theme_table were the only ones listed in #1001990: theme_* functions use associative arrays with optional indexes, but use values without checking.
I'll try and merge the patches, and submit them here to the testbot - haven't done that before :-)
Is this helpful, or did I miss something?
Mike
Comment #10
MichaelCole commentedHi bellHead,
I just started working on a bunch of other functions in theme.inc with the similar pattern.
where null is whatever is most appropriate.
Comment #11
MichaelCole commentedHi bellHead,
I just put together a patch an now I see what you mean for doing all the functions together.
Duplicate of #1001990: theme_* functions use associative arrays with optional indexes, but use values without checking
Comment #12
Botros Geris commentedwhen i add the attributes index in the variables array the whole site stopped working why?????any suggestions
Comment #13
catchPlease open a new support request with your question, not this two year old issue.