function cpn_form_alter in Code per Node 7
Same name and namespace in other branches
- 6 cpn.module \cpn_form_alter()
Implements of hook_form_alter().
File
- ./
cpn.module, line 547 - Primary hook implementations.
Code
function cpn_form_alter(&$form, $form_state, $form_id) {
// Block form (editing any block, or creating a Block module block).
if ($form_id == 'block_admin_configure' or $form_id == 'block_add_block_form' and $form['module']['#value'] == 'block') {
$title = array();
// Load block data.
$cpn = array(
'css' => '',
'js' => '',
'noscript' => '',
);
if (!empty($form['delta']['#value'])) {
try {
$cpn = db_query("SELECT css, js, noscript FROM {block} WHERE module = :module AND delta = :delta", array(
':module' => $form['module']['#value'],
':delta' => $form['delta']['#value'],
))
->fetchAssoc();
} catch (Exception $e) {
watchdog('cpn', 'Error loading block records for CPN, were the database updates ran?');
}
}
// CSS.
if (user_access('administer code per node') || user_access('edit css per block')) {
$form['cpn']['css'] = array(
'#type' => 'textarea',
'#title' => t('CSS'),
'#default_value' => $cpn['css'],
'#description' => t('Custom CSS rules for this block. Do not include @style tags.', array(
'@style' => '<style>',
)),
);
$title[] = 'CSS';
}
// JS & NOSCRIPT.
if (user_access('administer code per node') || user_access('edit javascript per block')) {
$form['cpn']['js'] = array(
'#type' => 'textarea',
'#title' => t('JavaScript'),
'#default_value' => $cpn['js'],
'#description' => t('Custom JavaScript for this block. Do not include @script tags.', array(
'@script' => '<script>',
)),
);
$form['cpn']['noscript'] = array(
'#type' => 'textarea',
'#title' => t('NOSCRIPT'),
'#default_value' => $cpn['noscript'],
'#description' => t("Custom HTML to show if JavaScript is not enabled in the visitor's browser. Do not include @script tags.", array(
'@script' => '<noscript>',
)),
);
$title[] = 'JavaScript';
}
// Fieldset.
if (isset($form['cpn'])) {
$form['cpn']['#type'] = 'fieldset';
$form['cpn']['#title'] = t(join(' & ', $title));
$form['cpn']['#tree'] = TRUE;
$form['cpn']['#group'] = 'visibility';
$form['submit']['#weight'] = 5;
$form['#validate'][] = 'cpn_block_validate';
$form['#submit'][] = 'cpn_block_submit';
cpn_attach_syntax_highlighting($form['cpn'], isset($form['cpn']['css']), isset($form['cpn']['js']));
}
}
}