You are here

function dynamicload_form_alter in Javascript Tools 5

Implementation of hook_form_alter().

File

dynamicload/dynamicload.module, line 234
Enable AJAX-based loading of selected page elements.

Code

function dynamicload_form_alter($form_id, &$form) {
  if ($form_id == 'block_admin_configure') {
    $options = array(
      'content' => t('Main content area'),
    );
    $result = db_query('SELECT module, delta FROM {blocks} WHERE status = 1 AND NOT (module = "%s" AND delta = "%s")', $form['module']['#value'], $form['delta']['#value']);
    while ($block = db_fetch_object($result)) {
      $module_blocks = module_invoke($block->module, 'block', 'list');
      $options['#block-' . $block->module . '-' . $block->delta] = t('Block: !info', array(
        '!info' => $module_blocks[$block->delta]['info'],
      ));
    }
    $regions = system_region_list(variable_get('theme_default', 'garland'));

    // Highlight regions on page to provide visual reference.
    foreach ($regions as $key => $value) {
      drupal_set_content($key, '<div class="block-region">' . $value . '</div>');
      $options['region-' . $key] = t('Region: !name', array(
        '!name' => $value,
      ));
    }
    $settings = dynamicload_block_data($form['module']['#value'], $form['delta']['#value']);
    $form['#submit']['dynamicload_submit'] = array();
    $form['dynamicload'] = array(
      '#type' => 'fieldset',
      '#title' => t('Dynamic loading'),
      '#collapsible' => true,
      '#weight' => -5,
    );
    $form['dynamicload']['dynamicload_apply'] = array(
      '#type' => 'checkbox',
      '#title' => t('Apply dynamic loading'),
      '#description' => t('Check if you want links on this block to be loaded dynamically rather than through a regular page refresh. If you enable this functionality for a block, make sure that you thoroughly test the result, as not all pages will perform as expected when loaded dynamically.'),
      '#default_value' => $settings['apply'] ? 1 : 0,
    );
    $form['dynamicload']['dynamicload_target'] = array(
      '#type' => 'select',
      '#title' => t('Target area'),
      '#default_value' => $settings['target'] ? $settings['target'] : '#main',
      '#options' => $options,
      '#description' => t('Select the page area for this block\'s links to load into. Only enabled blocks are available.'),
    );
    $options = array(
      DYNAMICLOAD_HTML => t('replace existing content'),
      DYNAMICLOAD_APPEND => t('append: add at end of existing content'),
      DYNAMICLOAD_PREPEND => t('prepend: add at beginning of existing content'),
      DYNAMICLOAD_BEFORE => t('before: add before target element'),
      DYNAMICLOAD_AFTER => t('after: add after target element'),
    );
    $form['dynamicload']['dynamicload_method'] = array(
      '#type' => 'select',
      '#title' => t('Appending method'),
      '#default_value' => $settings['method'] ? $settings['method'] : 1,
      '#options' => $options,
      '#description' => t('Select the way you want newly loaded content to be written to the target area.'),
    );
    $form['dynamicload']['dynamicload_refresh'] = array(
      '#type' => 'checkbox',
      '#title' => t('Automatically refresh this block'),
      '#default_value' => $settings['refresh'] ? 1 : 0,
    );
    $form['dynamicload']['dynamicload_refresh_interval'] = array(
      '#type' => 'select',
      '#title' => t('Block refresh interval'),
      '#description' => t('Select the interval at which this block should refresh.'),
      '#default_value' => $settings['refresh_interval'] ? $settings['refresh_interval'] : 30000,
      '#options' => array(
        5000 => t('five seconds'),
        10000 => t('ten seconds'),
        30000 => t('thirty seconds'),
        60000 => t('one minute'),
        120000 => t('two minutes'),
        180000 => t('three minutes'),
        300000 => t('five minutes'),
        600000 => t('ten minutes'),
      ),
    );
    $form['dynamicload']['dynamicload_scroll'] = array(
      '#type' => 'checkbox',
      '#title' => t('Scroll in new items'),
      '#description' => t('Check if you want new items for this block to scroll in ticker-style as they arrive (with the oldest item scrolling out). If this option is not checked, the whole block will refresh. Note: only works for items that come in as a list (using an HTML ul element).)'),
      '#default_value' => $settings['scroll'] ? 1 : 0,
    );
  }
}