I have been trying for hours to create a module to use tokens with the picture module but with no luck. The reason I can't make it work is due to this module being installed as it's conditions when generating the replacement values are very strict.

My replacement token (from the code below) uses the picture theme function.

  if ($type == 'image-field' && !empty($data['image-field'])) {

    foreach ($tokens as $token => $original) {
      
      $breakpoint_groups = breakpoints_breakpoint_group_load_all();

      if (array_key_exists($token, $breakpoint_groups )) {

        $output = '';
        foreach ($data['image-field'] as $field) {
          $item['item'] = $field;
          $mappings = picture_mapping_load($token);
          $breakpoint_styles = picture_get_mapping_breakpoints($mappings);
          $item['breakpoints'] = $breakpoint_styles;
          $item['uri'] = $item['item']['uri'];
          $output = theme('picture', $item);

          if (isset($tokens[$token])) {
            $replacements[$original] = $output;
          }
        }
      }
    }
  }

  return $replacements;

The tokens I generate look something like [node:field-image:picture_group_name]

if ($attribute == 'render') {
          $output[] = theme('image_formatter', array('item' => $field, 'image_style' => $type));
        }
        elseif (isset($attribute) && !empty($attribute)) {
          $output[] = $field[$attribute];
        }
        else {
          $output[] = image_style_url($token, $field['uri']);
        }

So what seems to happen is your module runs the final else condition above. Then my module runs it's conditions and add an item to the array which messes everything up.

The only way I can see to make this work is to patch this module so there is a condition where the replacement does not get generated.

This leave us with 2 options:
a) Add support for the picture module as part of it's core functionality
b) Add another token attribute so other models can work with the image field and this module ignores that field. [node:field-image:custom]

I am happy to work on a patch I just need to know which you would prefer.

Thanks

Gareth

Comments

DamienMcKenna’s picture

Component: Code » Integration with other media modules
Chris Matthews’s picture

I am happy to work on a patch I just need to know which you would prefer.

@DamienMcKenna, are you able to advise ☝︎

DamienMcKenna’s picture

Category: Support request » Feature request

I'm honestly not sure.

The purpose of this module is to provide tokens for values of images after they're processed through image styles, using server-side logic. The Picture module provides a wrapper for image styles based upon different breakpoints depending upon the visitor's browser, using client-side logic, but at the server side uses image styles to process the images. So I don't see what benefit this would give?