You are here

function theme_image_attach_attached_images in Image 6

Generic theme function for any set of attached images.

Parameters

$nid: The id of the attaching node.

$image_nodes: The fully loaded image nodes to theme. These do not need to be checked for access: that happens in this function.

$options: An associative array of options, with the following keys:

  • 'size' (default IMAGE_THUMBNAIL) The name of the image derivative size at which to show the images, eg 'thumbnail'.
  • 'link' (default 'image') Whether and where the images should be linked. This should be one of:

    • 'image': link to the image node. Default.
    • 'node': link to the attaching node.
    • 'none': no link.
  • 'attributes' Extra attributes for the div around each image.
3 theme calls to theme_image_attach_attached_images()
image_attach_views_handler_field_attached_images::render in contrib/image_attach/image_attach_views_handler_field_attached_images.inc
Render the field.
theme_image_attach_attached_images_block in contrib/image_attach/image_attach.module
Theme the attached images block.
theme_image_attach_attached_images_node in contrib/image_attach/image_attach.module
Theme attached images shown in nodes.

File

contrib/image_attach/image_attach.module, line 755
image_attach.module

Code

function theme_image_attach_attached_images($nid, $image_nodes = array(), $options = array()) {

  // Merge in defaults.
  $options += array(
    'size' => IMAGE_THUMBNAIL,
    'link' => 'image',
    'attributes' => array(),
  );
  $img_size = $options['size'];
  $link_destination = $options['link'];

  // Link images to the attaching node.
  if ($link_destination == 'node') {
    $link_path = "node/{$nid}";
  }
  $output = '';
  foreach ($image_nodes as $image) {
    if (!node_access('view', $image)) {

      // If the image is restricted, don't show it as an attachment.
      continue;
    }

    // Link images to the image node.
    if ($link_destination == 'image') {
      $link_path = "node/{$image->nid}";
    }

    // Get a fresh copy of the attributes for each image node.
    $div_attributes = $options['attributes'];

    // Create CSS classes, beginning with those passed in to the function.
    $classes = array();
    if (isset($div_attributes['class'])) {
      $classes[] = $div_attributes['class'];
    }

    // replace with base class in DIV

    //$classes[] = 'image-attach-' . $teaser_or_body;
    $classes[] = 'image-attach-node-' . $image->nid;
    if (!$image->status) {
      $classes[] = 'image-unpublished';
    }
    $div_attributes['class'] = implode(' ', $classes);

    // Add the width as inline CSS.
    $info = image_get_info(file_create_path($image->images[$img_size]));
    if (!isset($div_attributes['style'])) {
      $div_attributes['style'] = '';
    }
    $div_attributes['style'] .= 'width: ' . $info['width'] . 'px;';
    $output .= '<div' . drupal_attributes($div_attributes) . '>';
    $image_img = image_display($image, $img_size);
    if (isset($link_path)) {
      $output .= l($image_img, $link_path, array(
        'html' => TRUE,
      ));
    }
    else {
      $output .= $image_img;
    }
    $output .= "</div>\n";
  }
  return $output;
}