You are here

jquery_countdown_block.admin.inc in jQuery Countdown 6

Provides infrequently used functions for jquery_countdown_block.

File

jquery_countdown_block/jquery_countdown_block.admin.inc
View source
<?php

/**
 * @file
 * Provides infrequently used functions for jquery_countdown_block.
 */

/**
 * Form builder for the countdown block deletion form.
 */
function jquery_countdown_block_delete(&$form_state, $delta = 0) {
  $block_settings = variable_get("jquery_countdown_block_{$delta}_settings", NULL);
  $title = isset($block_settings['admin_title']) ? $block_settings['admin_title'] : 'Countdown Block ' . $delta;
  $form['block_title'] = array(
    '#type' => 'value',
    '#value' => $title,
  );
  $form['delta'] = array(
    '#type' => 'value',
    '#value' => $delta,
  );
  return confirm_form($form, t('Are you sure you want to delete the "%name" block?', array(
    '%name' => $title,
  )), 'admin/build/block', NULL, t('Delete'), t('Cancel'));
}

/**
 * Form submission handler for jquery_countdown_block_delete().
 */
function jquery_countdown_block_delete_submit($form, &$form_state) {

  // Remove the menu block configuration variables.
  $delta = $form_state['values']['delta'];
  $block_ids = variable_get('jquery_countdown_block_ids', array());
  unset($block_ids[array_search($delta, $block_ids)]);
  sort($block_ids);
  variable_set('jquery_countdown_block_ids', $block_ids);
  variable_del('jquery_countdown_block_' . $delta . '_settings');
  db_query("DELETE FROM {blocks} WHERE module = 'jquery_countdown_block' AND delta = %d", $delta);
  db_query("DELETE FROM {blocks_roles} WHERE module = 'jquery_countdown_block' AND delta = %d", $delta);
  drupal_set_message(t('The "%name" block has been deleted.', array(
    '%name' => $form_state['values']['block_title'],
  )));
  cache_clear_all();
  $form_state['redirect'] = 'admin/build/block';
  return;
}

/**
 * Returns the 'list' $op info for hook_block().
 */
function _jquery_countdown_block_block_list() {
  $blocks = array();
  foreach (variable_get('jquery_countdown_block_ids', array()) as $delta) {
    $block_settings = variable_get('jquery_countdown_block_' . $delta . '_settings', NULL);
    $blocks[$delta]['info'] = isset($block_settings['admin_title']) ? $block_settings['admin_title'] : 'Countdown Block ' . $delta;
    $blocks[$delta]['cache'] = BLOCK_CACHE_GLOBAL;
  }
  return $blocks;
}

/**
 * Returns the 'configure' $op info for hook_block().
 */
function _jquery_countdown_block_block_configure($delta) {
  $form = array();

  // get all stored values
  $block_settings = variable_get('jquery_countdown_block_' . $delta . '_settings', array());

  // get our settings form elements from base module give current settings as attribute so we get always the right defaults.
  $form = array_merge($form, _jquery_countdown_settings_form($block_settings));
  return $form;
}

/**
 * Returns the 'save' $op info for hook_block().
 */
function _jquery_countdown_block_block_save($delta, $edit) {
  variable_set('jquery_countdown_block_' . $delta . '_settings', $edit['jquery_countdown']);
}

Functions

Namesort descending Description
jquery_countdown_block_delete Form builder for the countdown block deletion form.
jquery_countdown_block_delete_submit Form submission handler for jquery_countdown_block_delete().
_jquery_countdown_block_block_configure Returns the 'configure' $op info for hook_block().
_jquery_countdown_block_block_list Returns the 'list' $op info for hook_block().
_jquery_countdown_block_block_save Returns the 'save' $op info for hook_block().