You are here

function ajaxblocks_form_block_admin_configure_alter in Ajax Blocks 6

Same name and namespace in other branches
  1. 7 ajaxblocks.module \ajaxblocks_form_block_admin_configure_alter()

Implements hook_form_FORM_ID_alter(). Adds AJAX settings to the block configure page.

File

./ajaxblocks.module, line 28
Loads dynamic blocks on cached page for anonymous users by performing AJAX request.

Code

function ajaxblocks_form_block_admin_configure_alter(&$form, &$form_state) {

  // Retrieve current setting for this block.
  $block_id = $form['module']['#value'] . '-' . $form['delta']['#value'];
  $settings = array();
  $value = (int) ajaxblocks_is_ajax($block_id, $settings);

  // AJAX settings fieldset.
  $form['ajaxblocks'] = array(
    '#type' => 'fieldset',
    '#title' => t('AJAX settings'),
    '#description' => t('The settings for loading the block via AJAX request made after the page loading. This method is used for anonymous user only, and the whole page must be cached.'),
    '#weight' => 1,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  if (module_exists('authcache')) {
    $form['ajaxblocks']['ajaxblocks_warning'] = array(
      '#type' => 'markup',
      '#value' => t("Authcache module is installed. Please check <a href=\"@settings\">settings</a> and make sure it doesn't cache AJAX requests to page (Drupal path) 'ajaxblocks'.", array(
        '@setings' => url('admin/settings/performance/authcache'),
      )),
    );
  }
  $form['ajaxblocks']['ajaxblocks_is_ajax'] = array(
    '#type' => 'select',
    '#title' => t('Load block via AJAX'),
    '#description' => t("Select \"yes\" if this block has dynamic content and isn't displayed correctly on cached pages."),
    '#options' => array(
      0 => t('no'),
      1 => t('yes'),
    ),
    '#default_value' => $value,
  );
  $picture_dir = base_path() . drupal_get_path('module', 'ajaxblocks') . '/images/';
  $pictures = array(
    0 => t('None'),
  );
  for ($i = 1; $i <= 8; $i++) {
    $pictures[$i] = '<img alt="" src="' . $picture_dir . 'loader-' . $i . '.gif" />';
  }
  $form['ajaxblocks']['ajaxblocks_loader_picture'] = array(
    '#type' => 'radios',
    '#title' => t('Loader picture'),
    '#description' => t('Choose the background picture for the block for AJAX loadding period.'),
    '#options' => $pictures,
    '#default_value' => isset($settings['loader_picture']) ? $settings['loader_picture'] : 0,
  );
  $form['ajaxblocks']['ajaxblocks_is_late'] = array(
    '#type' => 'select',
    '#title' => t('JavaScript event which initiates block loading'),
    '#description' => t('Select "DOM.ready event" if you want to load the block as soon as possible (this makes better experience on cached pages).'),
    '#options' => array(
      0 => t('DOM.ready event'),
      1 => t('window.onload event'),
    ),
    '#default_value' => isset($settings['is_late']) ? $settings['is_late'] : 0,
  );
  $form['ajaxblocks']['ajaxblocks_delay'] = array(
    '#type' => 'textfield',
    '#size' => 6,
    '#maxlength' => 6,
    '#title' => t('Time in milliseconds to wait before block loading'),
    '#description' => t('You can defer block loading and create interesting effects if necessary.'),
    '#default_value' => isset($settings['delay']) ? intval($settings['delay']) : 0,
  );
  $form['ajaxblocks']['ajaxblocks_include_noscript'] = array(
    '#type' => 'select',
    '#title' => t('Include NOSCRIPT tag with original block content'),
    '#description' => t('Original block content can be included in HTML code of the pages for browsers which do not support JavaScript. On cached pages, this content will be static.'),
    '#options' => array(
      0 => t('no'),
      1 => t('yes'),
    ),
    '#default_value' => isset($settings['include_noscript']) ? $settings['include_noscript'] : 1,
  );
  $all_roles = user_roles();
  $form['ajaxblocks']['ajaxblocks_cached_roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Load the block on cached pages for these roles only'),
    '#description' => t('Only anonymous role is necesary to be selected for most cases.'),
    '#options' => $all_roles,
    '#default_value' => isset($settings['cached_roles']) ? $settings['cached_roles'] : array(
      1,
    ),
  );
  $form['ajaxblocks']['ajaxblocks_uncached_roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Load the block on uncached pages for these roles only'),
    '#description' => t("Don't select any role unless you use authcache module or want to load this block via AJAX even on uncached pages."),
    '#options' => $all_roles,
    '#default_value' => isset($settings['uncached_roles']) ? $settings['uncached_roles'] : array(),
  );
  $form['submit']['#weight'] = 2;
  $form['#submit'][] = 'ajaxblocks_save_settings';
}