Hi!

I have the feeling that the D7 Version ignores the grouping completely. In the D6 Version is a switch block thats set's the rel attribut if I turn on grouping per node.

In the D6 Version of admin.inc is this option group

 // ImageField module:
  if (module_exists('imagefield')) {
    $data['imagefield'] = array(
      '#type' => 'fieldset',
      '#title' => t('ImageField module'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );

    $data['imagefield']['grouping'] = array(
      '#type' => 'radios',
      '#title' => t('Grouping'),
      '#options' => array(1 => t('Group per field'), 2 => t('Group all fields on page'), 0 => t('No grouping')),
      '#default_value' => isset($settings['imagefield']['grouping']) ? $settings['imagefield']['grouping'] : 1,
    );

    $data['imagefield']['use_list_field'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show only listed images'),
      '#description' => t('By default, Fancybox will display all the images. Check this to show only images marked listed.'),
      '#default_value' => isset($settings['imagefield']['use_list_field']) ? $settings['imagefield']['use_list_field'] : FALSE,
    );

 

This is used later in the .module file around line 588

/**
 * Implementation of hook_field_formatter().
 */
function fancybox_imagefield_image_imagecache($field, $item, $formatter, $node) {
  $settings = variable_get('fancybox_settings', array());

  if ($settings['imagefield']['use_list_field'] && $item['list'] == 0) {
	return null;
  }

  if (!isset($item['filepath']) && isset($item['fid'])) {
    $file = field_file_load($item['fid']);
    $item['filepath'] = $file['filepath'];
  }

  // Image caption.
  $item_data = $item['data'];
  $image_title = $item_data['description'];
  $image_title = (!empty($image_title) ? $image_title : $item_data['title']);
  $image_title = (!empty($image_title) ? $image_title : $item_data['alt']);

  if ($settings['imagefield']['use_node_title']) {
    $image_title = $node->title;
  }

  $loop_item = '';
  $nid = $item['nid'] ? $item['nid'] : ($node->nid ? $node->nid : '');
  switch ($settings['imagefield']['grouping']) {
    case 1:
      $loop_item = $nid .'-'. $field;
      break;
    case 2:
      $loop_item = 'all';
      break;
  }

  list($namespace, $presetname) = explode('|', $formatter, 2);

  if ($preset = imagecache_preset_by_name($namespace)) {
    return theme('imagefield_image_imagecache_fancybox', $namespace, $field, $item['filepath'], $image_title, $loop_item);
  }
}

 

How is this ment to work in the D7 version? I can't find any place where this admin settings are used. Is this working completely different in D7?

/**
 * Implementation of hook_field_formatter_view().
 */
function fancybox_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $settings = variable_get('fancybox_settings', array());

  $element = array();

  // Check if the formatter involves a particular image style.
  $matches = array();
  if (preg_match('/([a-z0-9_]+)_fancybox/', $display['type'], $matches)) {
    $image_style = $matches[1];
  }

  // Check if the formatter involves a link.
  if (strpos($display['type'], 'image_link_content') === 0) {
    $uri = entity_uri($entity_type, $entity);
  }
  elseif (strpos($display['type'], 'image_link_file') === 0) {
    $link_file = TRUE;
  }

  foreach ($items as $delta => $item) {
    if (isset($link_file)) {
      $uri = array(
        'path' => file_create_url($item['uri']),
        'options' => array(),
      );
    }

    //$href_uri = 'public://styles/fancybox/' . $item['filename'];
    $style_name = isset($settings['imagefield']['imagecache_preset']) ? $settings['imagefield']['imagecache_preset'] : 0;
    if ($style_name) {
      $style_path = image_style_path($style_name, $item['uri']);
      if (!file_exists($style_path)) {
        $style_path = image_style_url($style_name, $item['uri']);
      }
      $variables['path'] = file_create_url($style_path);
    }
    else {
      $style_path = file_create_url($item['uri']);
    }
    $href = file_create_url($style_path);

    $element[$delta] = array(
      '#theme' => 'image_formatter',
      '#item' => $item,
      '#image_style' => isset($image_style) ? $image_style : '',
      //'#path' => isset($uri) ? $uri : '',
      '#path' => array(
        'path' => $href,
        'options' => array(
          'attributes' => array(
            'class' => array('imagefield-fancybox'),
          ),
        ),
      ),
    );
  }

  return $element;
}


Comments

dalberts69’s picture

Quick and dirty, using the version posted here: http://drupal.org/node/1163604

I took the grouping settings and did some modifications

Edit: Moved $rel to above to declare - errored if config options not set.

Line 549 add:

<?php 
    $rel;
    if(isset($settings['imagefield']['grouping'])){

        switch($settings['imagefield']['grouping']){
            case 1:
                $rel = $field['field_name'];
            break;
            case 2:
                $rel = 'all-images';
            break;
            default:
                $rel = '';       
        }
    }  
?>

Then at 559 add the rel class to the attributes

<?php 
    $element[$delta] = array(
      '#theme' => 'image_formatter',
      '#item' => $item,
      '#image_style' => isset($image_style) ? $image_style : '',
      //'#path' => isset($uri) ? $uri : '',
      '#path' => array(
        'path' => $href,
        'options' => array(
          'attributes' => array(
            'class' => array('imagefield-fancybox'),
            'rel' => $rel
          ),
        ),
      ),
    );
  }
?>
aquamars’s picture

GENIUS

dalberts69’s picture

Slight mod after I noticed that it errors if the config options aren't set. Moved $rel to above to declare the variable. See above.

klonos’s picture

subscribing...

bas.hr’s picture