function nodesinblock_form_alter in Nodes In Block 6
Implementation of hook_form_alter(). Add Nodes in block fieldset.
File
- ./
nodesinblock.module, line 85 - Nodes in block makes it possible to add multiple nodes in one block.
Code
function nodesinblock_form_alter(&$form, $form_state, $form_id) {
$saved_types = variable_get('nodesinblock_contenttypes', array());
if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id && isset($saved_types[$form['#node']->type]) && $saved_types[$form['#node']->type] != '0') {
$a = 1;
$i = 0;
$block_options[-1] = t('None');
$deltas = variable_get('nodesinblock_' . $form['#node']->type . '_block', array());
foreach ($deltas as $key => $value) {
if ($deltas[$a] != 0) {
$block_name = check_plain(variable_get('nodesinblock_friendlyname_' . $i, t('Nodes in block ' . $a)));
$type = variable_get('nodesinblock_visibility_' . $i, '1') == '1' ? t('(Pos)') : t('(Neg)');
$block_options[$i] = $block_name . ' ' . $type;
}
$a++;
$i++;
}
if (!empty($block_options)) {
$node_info = array(
'weight' => 0,
'visibility' => '*',
'delta' => -1,
'render' => NIB_RENDER_PAGE_WITHOUT_LINKS,
);
if (!empty($form_state['values'])) {
$node_info['visibility'] = $form_state['values']['nodesinblock_visibility'];
$node_info['weight'] = $form_state['values']['nodesinblock_weight'];
$node_info['delta'] = $form_state['values']['nodesinblock_delta'];
$node_info['render'] = $form_state['values']['nodesinblock_render'];
}
elseif (!empty($form['nid']['#value'])) {
$node_info = db_fetch_array(db_query("SELECT * FROM {nodesinblock} WHERE nid = %d", $form['nid']['#value']));
}
else {
if (variable_get('nodesinblock_referer', FALSE) && isset($_SERVER['HTTP_REFERER'])) {
$end = '';
if (substr($_SERVER['HTTP_REFERER'], -1) === '/') {
$end = '/';
}
$base = url(NULL, array(
'absolute' => TRUE,
)) . $end;
if (strpos($_SERVER['HTTP_REFERER'], $base) === 0) {
$node_info['visibility'] = str_replace($base, '', $_SERVER['HTTP_REFERER']);
}
}
$node_info['render'] = '';
}
$form['nodesinblock'] = array(
'#type' => 'fieldset',
'#title' => check_plain(variable_get('nodesinblock_' . $form['#node']->type . '_label', t('Nodes in block'))),
'#collapsible' => variable_get('nodesinblock_' . $form['#node']->type . '_collapsible', TRUE),
'#collapsed' => variable_get('nodesinblock_' . $form['#node']->type . '_collapsed', TRUE),
);
$nodesinblock_enable = TRUE;
if (user_access('deny configuration on node form') && $GLOBALS['user']->uid != 1) {
$nodesinblock_enable = FALSE;
$form['nodesinblock']['#access'] = FALSE;
}
$form['nodesinblock']['nodesinblock_enable'] = array(
'#type' => 'hidden',
'#value' => $nodesinblock_enable,
);
$form['nodesinblock']['nodesinblock_delta'] = array(
'#type' => 'select',
'#title' => t('Select region'),
'#options' => $block_options,
'#default_value' => $node_info['delta'],
'#description' => t('The code between the round brackets indicate the visibility setting of the block.<br />Pos = Show on only the listed pages.<br />Neg = Show on every page except the listed pages.'),
);
$form['nodesinblock']['nodesinblock_weight'] = array(
'#type' => 'value',
'#value' => $node_info['weight'],
);
$form['nodesinblock']['nodesinblock_render'] = array(
'#type' => 'select',
'#title' => t('Render node as'),
'#options' => _nodesinblock_render_status(0),
'#default_value' => $node_info['render'],
);
if (variable_get('nodesinblock_' . $form['#node']->type . '_render', '0') != '0') {
$form['nodesinblock']['nodesinblock_render']['#type'] = 'value';
$form['nodesinblock']['nodesinblock_render']['#value'] = variable_get('nodesinblock_' . $form['#node']->type . '_render', 0);
}
$form['nodesinblock']['nodesinblock_visibility'] = array(
'#title' => t('Visibility'),
'#type' => 'textarea',
'#description' => t('Enter one page per line as Drupal paths. The \'*\' character is a wildcard. Example paths are blog for the blog page and blog/* for every personal blog. <front> is the front page.'),
'#default_value' => $node_info['visibility'],
'#wysiwyg' => FALSE,
);
}
}
}