You are here

popup_block.module in Popup 6.x

File

modules/popup_block/popup_block.module
View source
<?php

/**
 * Implementation of hook_form_alter
 * Adds UI settings to block configuration
 */
function popup_block_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'block_admin_configure' && $form['module']['#value'] != 'popup_menu') {
    module_load_include('inc', 'popup_ui', 'includes/popup_ui.admin');
    $settings = _popup_block_settings();
    $block_settings = $settings[$form['module']['#value'] . ':' . $form['delta']['#value']];
    $format_options = array_keys(_popup_ui_formatter_settings());
    array_unshift($format_options, 'Default');
    $display_format_options = array_combine($format_options, $format_options);
    $form['popup'] = array(
      '#type' => 'fieldset',
      '#title' => t('Block popup settings'),
      '#collapsible' => 1,
      'popup-block' => array(
        '#default_value' => $block_settings['active'],
        '#description' => t('This will render the block with the body initially invisible. When a user hovers over or clicks on the title, the body is displayed.'),
        '#title' => t('Display this block as a popup'),
        '#type' => 'checkbox',
      ),
      'popup-block-format' => array(
        '#default_value' => $block_settings['format'],
        '#title' => 'Display format',
        '#type' => 'select',
        '#options' => $display_format_options,
        '#description' => t('Select the format in which to display popups. You may manage popup formats !here.', array(
          '!here' => l('here', 'admin/settings/popup/formats'),
        )),
      ),
    );
    $form['submit']['#weight'] = 10;
    $form['#submit'][] = 'popup_block_form_submit';
  }
}

/**
 *  Implementation of hook_features_api
 */
function popup_block_features_api() {
  return array(
    'popupblock' => array(
      'name' => t('Popup blocks'),
      'default_hook' => 'popupblock_defaults',
      'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON,
      'file' => drupal_get_path('module', 'popup_block') . '/includes/popup_block.features.inc',
    ),
  );
}

/* ---- Themeing hooks ---- */
function popup_block_preprocess_block(&$variables) {
  module_load_include('inc', 'popup', 'includes/popup.api');
  $settings = _popup_block_settings();
  $block = $variables['block'];
  $block_settings = $settings[$block->module . ':' . $block->delta];
  if ($block_settings && $block_settings['active']) {
    $attributes = array();
    $attributes['block'] = 1;
    $attributes['format'] = $block_settings['format'];
    $attributes['module'] = $block->module;
    $attributes['delta'] = $block->delta;
    $variables['block']->content = popup_element($block->subject, $block->content, $attributes);
    $variables['block']->subject = '';
  }
}

/* ---- Forms ---- */
function popup_block_form_submit(&$form, &$form_state) {
  $settings = _popup_block_settings();
  $values = $form_state['values'];
  $settings[$values['module'] . ':' . $values['delta']] = array(
    'active' => $values['popup-block'],
    'format' => $values['popup-block-format'],
  );
  _popup_block_settings($settings);
}

/* ---- Settings ---- */
function _popup_block_settings($new_settings = FALSE) {
  static $settings = FALSE;
  if ($new_settings) {
    $settings = $new_settings;
    variable_set('popup-block-settings', $settings);
  }
  if (!$settings) {
    $settings = variable_get('popup-block-settings', array());
  }
  return $settings;
}

Functions

Namesort descending Description
popup_block_features_api Implementation of hook_features_api
popup_block_form_alter Implementation of hook_form_alter Adds UI settings to block configuration
popup_block_form_submit
popup_block_preprocess_block
_popup_block_settings