You are here

function image_attach_block in Image 6

Same name and namespace in other branches
  1. 5.2 contrib/image_attach/image_attach.module \image_attach_block()
  2. 5 contrib/image_attach/image_attach.module \image_attach_block()

Implementation of hook_block().

File

contrib/image_attach/image_attach.module, line 55
image_attach.module

Code

function image_attach_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0] = array(
        'info' => t('Attached images'),
        'weight' => 0,
        'visibility' => 1,
        'pages' => 'node/*',
      );
      return $blocks;
    case 'view':
      if ($delta == 0) {
        if (arg(0) == 'node' && is_numeric(arg(1))) {
          $node = node_load(arg(1));
          if (isset($node->iids)) {
            $output['subject'] = t('Attached images');
            foreach ($node->iids as $iid) {
              $image = node_load($iid);
              if (node_access('view', $image)) {
                $image_nodes[] = $image;
              }
            }
            $output['content'] = theme('image_attach_attached_images_block', $node->nid, $image_nodes);
            return $output;
          }
        }
      }
      break;
    case 'configure':
      if ($delta == 0) {
        $image_sizes = array();
        foreach (image_get_sizes() as $key => $size) {
          $image_sizes[$key] = $size['label'];
        }
        $form['image_attach_block_0_size'] = array(
          '#type' => 'select',
          '#title' => t('Image size'),
          '#default_value' => variable_get('image_attach_block_0_size', IMAGE_THUMBNAIL),
          '#options' => $image_sizes,
          '#description' => t('This determines the size of the image that appears in the block.'),
        );
        return $form;
      }
      break;
    case 'save':
      if ($delta == 0) {
        variable_set('image_attach_block_0_size', $edit['image_attach_block_0_size']);
      }
      break;
  }
}