Upload Photo link in Image Gallery

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
cithukyaw's picture

Hi Drupalers

I have a link "Upload Photo" in image-view-image-gallery.tpl.php. It is created from mytheme_preprocess_image_view_image_gallery().

<?php
function mytheme_preprocess_image_view_image_gallery(&$vars, $hook){
    if(
user_access('create images')){
       
$view = $vars['view'];
      
$links[] = array('title' => 'Upload photo', 'href' => 'node/add/image','query'=>'tid='.$view->args[1]);
    }
 
$vars['links'] = $links;
}
?>

Here is the code for image-view-image-gallery.tpl.php

<?php print theme_links($links); ?>
<div class="item-list image-gallery-nodes clear-block">
  <?php if (!empty($title)): ?>
    <h3><?php print $title; ?></h3>
  <?php endif; ?>
  <<?php print $options['type']; ?> class="images">
    <?php foreach ($rows as $id => $row): ?>
      <li class="<?php print $classes[$id]; ?>"><?php print $row; ?></li>
    <?php endforeach; ?>
  </<?php print $options['type']; ?>>
</div>

But, when there is no image in the gallery, this link doesn't appear.
How can I do that ?