function theme_sarnia_schema_rule_form in Sarnia 7
Transforms the rules administration form into a table.
File
- ./
sarnia.rules.inc, line 243
Code
function theme_sarnia_schema_rule_form($variables) {
$form = $variables['form'];
$columns = array(
'enabled',
'search_api_server',
'match_type',
'match_value',
'effect',
'replacement',
'delete',
);
$header = array();
$rows = array();
$stripe = TRUE;
foreach (element_children($form['rules']) as $i) {
$element =& $form['rules'][$i];
$stripe = !$stripe;
// New rule title.
if (!$element['rule']['#value']->id) {
$row = array(
'data' => array(),
'no_striping' => TRUE,
'class' => array(
$stripe ? 'odd' : 'even',
),
);
$row['data'][] = array(
'data' => '<strong>' . t('Add a new rule:') . '</strong>',
'colspan' => count($columns),
);
$rows[] = $row;
}
// Rule form as row.
$row = array(
'data' => array(),
'no_striping' => TRUE,
'class' => array(
$stripe ? 'odd' : 'even',
),
);
foreach ($columns as $col) {
$row['data'][$col] = drupal_render($element[$col]);
if (empty($header[$col])) {
$header[$col] = isset($element[$col]['#title']) ? $element[$col]['#title'] : '';
}
}
$row['data']['search_api_server'] = array(
'data' => $row['data']['search_api_server'],
'width' => '20px',
);
$rows[] = $row;
// Rule description text.
if ($element['rule']['#value']->id) {
$row = array(
'data' => array(
'',
'',
),
'no_striping' => TRUE,
'class' => array(
$stripe ? 'odd' : 'even',
),
);
$color = isset($element['#sarnia_rule_color']) ? $element['#sarnia_rule_color'] : '';
$row['data'][] = array(
'data' => "<span style='{$color}' title='Rule ID " . $element['rule']['#value']->id . "'><em>" . _sarnia_get_rule_text($element['rule']['#value']) . '</em></span>',
'colspan' => count($columns) - 1,
);
$rows[] = $row;
}
}
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
'id' => 'sarnia-schema-rules',
),
));
$output .= drupal_render_children($form);
return $output;
}