You are here

function theme_matrix_preview in Matrix field 8.2

Same name and namespace in other branches
  1. 7.2 matrix.admin.inc \theme_matrix_preview()

Theme the display of the form

1 theme call to theme_matrix_preview()
matrix_field_settings_form_custom in ./matrix.admin.inc
Settings for for the custom matrix

File

./matrix.admin.inc, line 659
Configuration pages for matrix field

Code

function theme_matrix_preview($variables) {
  $form = $variables['form'];
  $cols_count = $form['#setup']['cols']['count'];
  $rows_count = $form['#setup']['rows']['count'];
  if ($rows_count == 0 || $cols_count == 0) {
    return '';

    //show nothing at all if either rows or columns = 0
  }

  //render first row (headers)
  $items = array();
  $items[] = '';

  // top left cell
  for ($i = 1; $i <= $cols_count; $i++) {
    $items[] = drupal_render($form['cols'][$i]['summary']) . drupal_render($form['cols'][$i]['button']) . drupal_render($form['cols'][$i]['edit-wrapper']);
  }
  $rows[] = $items;

  //render all subsequent rows
  for ($i = 1; $i <= $rows_count; $i++) {
    $items = array();
    $items[] = drupal_render($form['rows'][$i]['summary']) . drupal_render($form['rows'][$i]['button']) . drupal_render($form['rows'][$i]['edit-wrapper']);
    for ($j = 1; $j <= $cols_count; $j++) {
      $items[] = '';
    }
    $rows[] = $items;
  }
  $output = drupal_render($form['message2']);
  $output .= drupal_render($form['define']);
  $output .= _theme('table', array(
    'header' => NULL,
    'rows' => $rows,
    'attributes' => array(
      'border' => 1,
    ),
  ));
  $output .= drupal_render($form['form']);
  return $output;
}