You are here

function image_block in Image 6

Same name and namespace in other branches
  1. 5.2 image.module \image_block()
  2. 5 image.module \image_block()

Implementation of hook_block.

Offers 2 blocks: latest image and random image

File

./image.module, line 256

Code

function image_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $block[0]['info'] = t('Latest image');
      $block[1]['info'] = t('Random image');
      return $block;
    case 'configure':
      $form['number_images'] = array(
        '#type' => 'select',
        '#title' => t('Number of images to display'),
        '#options' => drupal_map_assoc(range(1, 99)),
        '#default_value' => variable_get("image_block_{$delta}_number_images", 1),
      );
      return $form;
    case 'view':
      if (user_access('access content')) {
        switch ($delta) {
          case 0:
            $images = image_get_latest(variable_get("image_block_{$delta}_number_images", 1));
            $block['subject'] = t('Latest image');
            $block['content'] = theme('image_block_latest', $images, IMAGE_THUMBNAIL);
            break;
          case 1:
            $images = image_get_random(variable_get("image_block_{$delta}_number_images", 1));
            $block['subject'] = t('Random image');
            $block['content'] = theme('image_block_random', $images, IMAGE_THUMBNAIL);
            break;
        }
      }
      return $block;
    case 'save':
      variable_set("image_block_{$delta}_number_images", $edit['number_images']);
      break;
  }
}