You are here

function nodeblock_form_alter in Nodeblock 5

Same name and namespace in other branches
  1. 6 nodeblock.module \nodeblock_form_alter()

Implementation of hook_form_alter().

File

./nodeblock.module, line 16

Code

function nodeblock_form_alter($form_id, &$form) {

  // content type settings form
  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
    $form['workflow']['nodeblock'] = array(
      '#type' => 'radios',
      '#title' => t('Available as block'),
      '#default_value' => variable_get('nodeblock_' . $form['#node_type']->type, 0),
      '#options' => array(
        0 => t('Disabled'),
        1 => t('Enabled'),
      ),
      '#description' => t('Should these nodes be made available as blocks?'),
    );
  }

  // node add/edit form
  if (isset($form['type'])) {
    $node = $form['#node'];

    // if enabled adjust the form
    if ($form_id == $form['type']['#value'] . '_node_form' && variable_get('nodeblock_' . $node->type, 0) && user_access('administer blocks')) {
      global $theme_key;
      $block = $node->nodeblock;

      // provided by nodeapi('prepare')
      $form['nodeblock'] = array(
        '#type' => 'fieldset',
        '#title' => t('Block Options'),
        '#tree' => true,
      );
      $block_regions = array(
        BLOCK_REGION_NONE => '<' . t('none') . '>',
      ) + system_region_list($theme_key);
      $form['nodeblock']['region'] = array(
        '#type' => 'select',
        '#title' => t('Region'),
        '#default_value' => $block['status'] ? isset($block['region']) ? $block['region'] : system_default_region($theme_key) : BLOCK_REGION_NONE,
        '#options' => $block_regions,
      );
      $form['nodeblock']['weight'] = array(
        '#type' => 'weight',
        '#title' => t('Weight'),
        '#default_value' => $block['weight'],
      );
    }
  }
}