function context_ui_form_alter in Context 5
Implementation of hook_form_alter().
File
- context_ui/
context_ui.module, line 268
Code
function context_ui_form_alter($form_id, &$form) {
if ($form['#node'] && arg(0) != 'admin') {
// Prevent this from firing on admin pages... damn form driven apis...
context_ui_set('node', $form['#node']->type);
}
else {
if ($form_id == 'comment_form' && ($nid = $form['nid']['#value'])) {
$node = node_load($nid);
context_ui_set('node', $node->type);
}
else {
if ($form_id == 'block_admin_configure') {
// Display context_ui visibility information on block configuration pages
$module = $form['module']['#value'];
$delta = $form['delta']['#value'];
$result = db_query("SELECT cb.cid, cb.region, c.namespace, c.attribute, c.value FROM {context_ui_block} cb JOIN {context_ui} c ON cb.cid = c.cid WHERE cb.module = '%s' AND cb.delta = '%s' AND c.status = %d", $module, $delta, 1);
$rows = array();
while ($row = db_fetch_object($result)) {
$rows[] = array(
$row->namespace,
$row->attribute,
$row->value,
$row->region,
l(t('Edit visibility'), 'admin/build/context/edit/' . $row->cid, array(), null, 'context-ui-blocks'),
);
}
if ($rows) {
$content = theme('table', array(
t('Namespace'),
t('Attribute'),
t('Value'),
t('Region'),
'',
), $rows);
}
else {
$content = "<p>" . t('No visibility rules have been set for this block using context_ui.') . "</p>";
}
$form['context_ui'] = array(
'#type' => 'fieldset',
'#title' => t('Context UI visibility'),
'#weight' => -1,
'#collapsible' => true,
);
$form['context_ui']['contexts'] = array(
'#type' => 'item',
'#value' => $content,
'#description' => t('To add or remove block visibility rules based on context, use the !context_admin.', array(
'!context_admin' => l(t('context administration page'), 'admin/build/context'),
)),
);
$form['block_settings']['#weight'] = -5;
}
}
}
}