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

droplet’s picture

MichaelCole’s picture

Status: Closed (duplicate) » Needs review
StatusFileSize
new1.25 KB

The 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:

  $html = theme_table( array( 'header'=>$header, 'rows'=>$rows) );
  $render_array['header_rows'] = array(
    '#markup' => $html,
  );

  $html = theme_table( array('rows'=>$rows) );
  $render_array['rows_only'] = array(
    '#markup' => $html,
  );

  $html = theme_table( array( 'header'=>$header) );
  $render_array['header_only'] = array(
    '#markup' => $html,
  );

  $html = theme_table( array() );  // <table></table>
  $render_array['none'] = array(
    '#markup' => $html,
  );
  return $render_array;

Status: Needs review » Needs work

The last submitted patch, theme_table.patch, failed testing.

MichaelCole’s picture

Status: Needs work » Closed (duplicate)
StatusFileSize
new1.26 KB

Same effect, better syntax for sticky.

MichaelCole’s picture

Status: Closed (duplicate) » Needs review

#2: theme_table.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, theme_table4.patch, failed testing.

MichaelCole’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB

How about a patch from the root :-)

bellHead’s picture

It 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?

MichaelCole’s picture

Hi 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

MichaelCole’s picture

Hi bellHead,

I just started working on a bunch of other functions in theme.inc with the similar pattern.

/**
 * Returns HTML for a breadcrumb trail.
 *
 * @param $variables
 *   An associative array containing:
 *   - breadcrumb: An array containing the breadcrumb links.
 */
function theme_breadcrumb($variables) {
  $breadcrumb = isset($variables['breadcrumb']) ? $variables['breadcrumb'] : null;

where null is whatever is most appropriate.

MichaelCole’s picture

Status: Needs review » Closed (duplicate)

Hi 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

Botros Geris’s picture

Priority: Normal » Critical
Status: Closed (duplicate) » Active

when i add the attributes index in the variables array the whole site stopped working why?????any suggestions

catch’s picture

Priority: Critical » Normal
Status: Active » Closed (duplicate)

Please open a new support request with your question, not this two year old issue.