You are here

function nodesinblock_settings in Nodes In Block 7

Same name and namespace in other branches
  1. 6 nodesinblock.admin.inc \nodesinblock_settings()

Menu callback to configure general settings for nodes in block.

1 string reference to 'nodesinblock_settings'
nodesinblock_menu in ./nodesinblock.module
Implements hook_menu().

File

./nodesinblock.admin.inc, line 11
Administration page for nodes in block.

Code

function nodesinblock_settings() {
  $form = array();
  $content_types = node_type_get_names();
  $saved_types = variable_get('nodesinblock_contenttypes', array());
  $form['nodesinblock'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#description' => t('Select number of blocks to create and associate content types which nodes can be used to insert as content in a block. When you change the number, be sure to goto the <a href="@url">block configuration</a> page so the block settings are updated in the database. When at least one content type is selected, two fieldsets will become available after clicking the submit button where you can change general settings and associate content types per block.', array(
      '@url' => url('admin/build/block'),
    )),
  );
  $form['nodesinblock']['nodesinblock_nrofblocks'] = array(
    '#type' => 'select',
    '#title' => t('Total number of blocks'),
    '#options' => drupal_map_assoc(array(
      1,
      2,
      3,
      4,
      5,
      6,
      7,
      8,
      9,
      10,
      11,
      12,
      13,
      14,
      15,
    )),
    '#default_value' => variable_get('nodesinblock_nrofblocks', 1),
  );
  $form['nodesinblock']['nodesinblock_contenttypes'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Content types'),
    '#options' => $content_types,
    '#default_value' => $saved_types,
  );
  $form['nodesinblock']['nodesinblock_referer'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use the referring page as the default value for <em>visibility</em> at the content node form'),
    '#default_value' => variable_get('nodesinblock_referer', FALSE),
    '#prefix' => '<strong>' . t('Creating and modifying blocks') . ':</strong>',
  );

  // Settings per block & content type.
  if (!empty($saved_types)) {
    $form['general_settings'] = array(
      '#type' => 'fieldset',
      '#title' => t('Settings per block'),
      '#description' => t('Note: if you set the visibility setting for the block as "<em>Show on every page except the listed pages</em>", multiple paths will not work correct because of the way that Drupal core block visibility works. You\'ll be better off choosing the default option. '),
    );
    for ($i = 0, $a = 1; $i < variable_get('nodesinblock_nrofblocks', 1); $i++, $a++) {
      $form['general_settings']['nodesinblock_friendlyname_' . $i] = array(
        '#type' => 'textfield',
        '#title' => t('User friendly name for block') . ' ' . $a,
        '#default_value' => check_plain(variable_get('nodesinblock_friendlyname_' . $i, t('Nodes in block ' . $a))),
        '#description' => t('Only use alphanumeric characters.'),
      );
      $form['general_settings']['nodesinblock_visibility_' . $i] = array(
        '#type' => 'select',
        '#title' => t('Visibility settings for block') . ' ' . $a,
        '#options' => array(
          t('Show on every page except the listed pages.'),
          t('Show on only the listed pages.'),
        ),
        '#default_value' => variable_get('nodesinblock_visibility_' . $i, '1'),
      );
    }
    $blocks = module_invoke('nodesinblock', 'block_info');
    $block_options = array();
    $a = 1;
    foreach ($blocks as $key => $value) {
      $block_options[$a] = $value['info'];
      $a++;
    }
    $form['contenttypes_block'] = array(
      '#type' => 'fieldset',
      '#title' => t('Settings per content type'),
      '#description' => t('Define per content type which blocks are available. On the content node form, a select box will be available to select the appropriate block where the node content must be displayed. You can also choose the label of the fieldset and if it is collapsible and/or collapsed by default. You can set a default render mode for the node. If you choose one, the select box on the node form will be hidden.'),
    );

    // Iterate over selected types
    foreach ($saved_types as $key => $value) {
      if ($value != '0') {
        $form['contenttypes_block']['nodesinblock_' . $key . '_block'] = array(
          '#type' => 'checkboxes',
          '#title' => t('Blocks'),
          '#options' => $block_options,
          '#default_value' => variable_get('nodesinblock_' . $key . '_block', array()),
          '#prefix' => '<div style="float: left; padding:5px; margin: 10px 5px 10px 0px; border: 1px solid #cccccc;"> <strong>' . t('Configure @key', array(
            '@key' => $key,
          )) . '</strong>',
        );
        $form['contenttypes_block']['nodesinblock_' . $key . '_label'] = array(
          '#type' => 'textfield',
          '#title' => t('Fieldset label'),
          '#default_value' => check_plain(variable_get('nodesinblock_' . $key . '_label', t('Nodes in block'))),
          '#size' => 20,
        );
        $form['contenttypes_block']['nodesinblock_' . $key . '_collapsed'] = array(
          '#type' => 'checkbox',
          '#title' => t('Collapsed fieldset'),
          '#default_value' => variable_get('nodesinblock_' . $key . '_collapsed', TRUE),
        );
        $form['contenttypes_block']['nodesinblock_' . $key . '_collapsible'] = array(
          '#type' => 'checkbox',
          '#title' => t('Collapsible fieldset'),
          '#default_value' => variable_get('nodesinblock_' . $key . '_collapsible', TRUE),
        );
        $options = array(
          0 => t('Let the user decide'),
        );
        $options += _nodesinblock_render_options();
        $form['contenttypes_block']['nodesinblock_' . $key . '_render'] = array(
          '#type' => 'select',
          '#title' => t('Render mode'),
          '#default_value' => variable_get('nodesinblock_' . $key . '_render', 0),
          '#options' => $options,
          '#suffix' => '</div>',
        );
      }
    }
  }

  // Don't use system_settings_form because we want
  // to have a warning screen when clearing configuration.
  $form['buttons']['submit'] = array(
    '#value' => t('Save configuration'),
    '#type' => 'submit',
    '#submit' => array(
      'nodesinblock_settings_save',
    ),
  );
  $form['buttons']['reset'] = array(
    '#value' => t('Clear configuration'),
    '#type' => 'submit',
    '#submit' => array(
      'nodesinblock_settings_clear_redirect',
    ),
  );
  return $form;
}