Download & Extend

Previous and Next links should disappear if there's only one image in the gallery

Project:Node Gallery
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:critical
Assigned:justintime
Status:closed (fixed)

Issue Summary

I think it would be nice if the Previous and Next links in the Image Navigator would disappear if there's only one image in the gallery.

Comments

#1

Priority:normal» critical
Assigned to:Anonymous» kmonty

Good catch.

#2

Hi kmoty,

the navigator is themed in the theme_gallery_image_navigator. Just see if the navigator total is smaller or equal 1 and in this case we return an empty $col2.

See the attached code it should work.

function theme_gallery_image_navigator($navigator, $image) {
  $col1 = array('data' => t("Image %current of %total", array('%current' => $navigator['current'], '%total' => $navigator['total'])),
    'class' => 'image-navigator-left');
  //DG lets see if the total of images is smaller or equal 1 and return an empty $col2
  if ($navigator['total'] <= 1) {
  $col2 = '';
  } else {
  if (variable_get('node_images_page_fragment', FALSE)) {
$col2 = array('data' => l('Previous', 'node/'. $navigator['prev_nid'],array(fragment => 'node-inner')) .'/'. l('Next', 'node/'. $navigator['next_nid'],array(fragment => 'node-inner')),
    'class' => 'image-navigator-mid');
  }
  else {
  $col2 = array('data' => l('Previous', 'node/'. $navigator['prev_nid']) .'/'. l('Next', 'node/'. $navigator['next_nid']),
    'class' => 'image-navigator-mid');
  }
  }
  $col3 = array('data' => node_gallery_operations('image', $image), 'class' => 'image-navigator-right');
  $rows[] = array($col1, $col2, $col3);

  return theme('table', NULL, $rows, array('class' => 'image-navigator'));
}

code is running here: http://photographer.freelens.ws
Dirk

#3

Tested this, works fine

#4

maybe dress it up a bit with this,,

  //DesignWork lets see if the total of images is smaller or equal 1 and return an empty $col2
  if ($navigator['total'] <= 1) {
  $col2 = 'This gallery has only one image.';
  } else {

#5

might as well post what I'm running if any one likes it.. I have been fixing the previous/next links every time I download it..

function theme_gallery_image_navigator($navigator, $image) {
  $col1 = array('data' => t("Image %current of %total", array('%current' => $navigator['current'], '%total' => $navigator['total'])),
    'class' => 'image-navigator-left');
  //DesignWork lets see if the total of images is smaller or equal 1 and return an empty $col2
  if ($navigator['total'] <= 1) {
  $col2 = 'This gallery has only one image.';
  } else {
  if (variable_get('node_images_page_fragment', FALSE)) {
$col2 = array('data' => l('< Previous Photo', 'node/'. $navigator['prev_nid'],array(fragment => 'node-inner')) .' | '. l('Next Photo >', 'node/'. $navigator['next_nid'],array(fragment => 'node-inner')),
    'class' => 'image-navigator-mid');
  }
  else {
  $col2 = array('data' => l('< Previous Photo', 'node/'. $navigator['prev_nid']) .' | '. l('Next Photo >', 'node/'. $navigator['next_nid']),
    'class' => 'image-navigator-mid');
  }
  }
  $col3 = array('data' => node_gallery_operations('image', $image), 'class' => 'image-navigator-right');
  $rows[] = array($col1, $col2, $col3);

  return theme('table', NULL, $rows, array('class' => 'image-navigator'));
}

EDIT: this holds the div open too so the 'back to gallery' doesn't go to 2 lines

#6

dbeall, what happens if you have an empty gallery? Does it say "This gallery has only one image."?

#7

yes, This gallery only has one photo, http://www.davebeall.com/node-gallery/one-image/050181jpg
and
my modified previous next links, http://www.davebeall.com/node-gallery/arctic-cat-lake/cat001

#8

Yes, but when you have zero, does it tell you that you have one?

#9

on a empty gallery there is no image, so you can not access it. But dbeall why we should say "only one image...", if I can see this in the image count on the left side anyway? For me that sounds obsolet. I would leave it empty.

Cheers

Dirk

#10

Ah, gotcha. If you guys work out the specifics, Ill commit the code.

#11

Thanks justintime :)

#12

it's ok with me, leave it blank. It's nice that the prev/next is gone with one image.

The only other thing the text does is hold the div open so the 'back to gallery' stays on one line...

#13

Hi dbeall,

we can make the array for (one image) like this: $col2 = array('data' =>t(' '), 'class' => 'image-navigator-mid'); this will probalby hold the div open.

#14

yes, that does the trick...
@@180
$col2 = array('data' =>t(' '), 'class' => 'image-navigator-mid');

#15

Can someone post the final code? I'll look it over and check it in - but I haven't been following the whole thread, so I don't know what goes and what doesn't. Best if someone involved closely with the issue posts the code.

#16

I'll leave this up to kmonty or DesignWork, developers know best. The rest of us can edit as needed or wanted.

#17

Hi justintime, dbeall

the final code

function theme_gallery_image_navigator($navigator, $image) {
  $col1 = array('data' => t("Image %current of %total", array('%current' => $navigator['current'], '%total' => $navigator['total'])),
    'class' => 'image-navigator-left');
  if ($navigator['total'] <= 1) {
  $col2 = array('data' =>t('&nbsp;'), 'class' => 'image-navigator-mid');
  } else {
  if (variable_get('node_images_page_fragment', FALSE)) {
$col2 = array('data' => l('Previous', 'node/'. $navigator['prev_nid'],array(fragment => 'node-inner')) .'/'. l('Next', 'node/'. $navigator['next_nid'],array(fragment => 'node-inner')),
    'class' => 'image-navigator-mid');
  }
  else {
  $col2 = array('data' => l('Previous', 'node/'. $navigator['prev_nid']) .'/'. l('Next', 'node/'. $navigator['next_nid']),
    'class' => 'image-navigator-mid');
  }
  }
  $col3 = array('data' => node_gallery_operations('image', $image), 'class' => 'image-navigator-right');
  $rows[] = array($col1, $col2, $col3);

  return theme('table', NULL, $rows, array('class' => 'image-navigator'));
}

function theme_gallery_meta($gallery) {
  $images_count = empty($gallery->images_count) ? count($gallery->images) : $gallery->images_count;
  $items[] = format_plural($images_count, '1 image', '@count images');
  $items[] = t('Created at: !date', array('!date' => format_date($gallery->created, 'custom', 'Y-m-d')));
 
  return $items;
}

so we can close this thread :)

Dirk

#18

Status:active» reviewed & tested by the community

@maintainers
This is not in the 6.x-2.x-dev Jan 11th download.
I added #17 to the Jan 11th dev and all is well that I can see

#19

Component:User interface» Code

I think this code.. since it is a hidden function

#20

Assigned to:kmonty» justintime
Status:reviewed & tested by the community» fixed

Committed.

DesignWork, this is very constructive criticism, so please don't take it the wrong way. We appreciate your code, and if you respond to me and say "I don't care about no stinkin' coding standards!", I'll still accept your code and clean it up before I commit it ;-)

The indentation was really messed up in that snippet, and the brackets for the 'else' were kinda funky. Here's the node on the "official" way to format code - http://drupal.org/node/1354. If you use Eclipse as your IDE, I can help you set it up so it does this for you automagically.

#21

Hi justintime,

no problem. I use Eclipse yes and just give me a hint how to change indentation settings. The funky else brackets is bad style from me, but I swear I will nerver do this again. (or at least control it before posting).

:)

Dirk

#22

If you're using Eclipse, check out this node: http://drupal.org/node/75242

Also checkout the PDT templates: http://groups.drupal.org/node/2663#comment-56688

The easiest way to give us code to commit, is to right click the file you've changed, go to Team->Create Patch. Point it at a file, then upload that file to the issue queue.

How are things coming on your CVS application?

#23

Hi justintime,

I´m waiting for kmonty to approve:)

#24

Ah - he said he was swamped. When I got approved for CVS, I only needed kmonty's approval, and at the time he was co-maintainer (wilson98 was maintainer). I think you'll be okay with just my approval. Give it a shot, and see what happens.

#25

I was going to make a patch from the supplied code and do some little house cleaning, but I don't want to step on anyone's toes... after all I don't know how to write the stuff.. But I know some of the format and patch generation stuff.. after working with Mickytown2 on project/boost and chasing patches for weeks on end, racing to get stable out before a presentation.
Next time, I will just do it instead of sitting here ringing the bell like a dummy. besides, you guys are busy doing the important stuff.

#26

actually there is still one item out of format
There is suppose to be a space after the comma for every part of the whatever.. $navigator['prev_nid'],array

if (variable_get('node_images_page_fragment', FALSE)) {
$col2 = array('data' => l('Previous', 'node/'. $navigator['prev_nid'],array(fragment => 'node-inner')) .'/'. l('Next', 'node/'. $navigator['next_nid'],array(fragment => 'node-inner')),
    'class' => 'image-navigator-mid');
  }

#27

Heh, nice catch. Committed.

#28

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here