3

Using ImageCache Actions there are 2 different Image Styles - e.g. S1 and S2.

What needs to happen:

  • User A has Role Y and when s/he views a node/user profile should always be presented with S1 images.
  • User B has Role Z and when s/he views a node/user profile should always be presented with S2 images.

What are the different ways this can be achieved? All suggestions very welcome.

2
  • Basically, in .php.tpl file, u need to use the global user, get the global user role. Then use a simple php if statement, If role = x then picture gets applied s1 style. If role = Y then S2. Sorry, I don't provide code answers.
    – No Sssweat
    Dec 28, 2015 at 1:40
  • I was thinking the same. But I'm still wondering if there's a way that doesn't involve the template files.
    – penname
    Dec 28, 2015 at 19:38

3 Answers 3

1

You can use a hook_preprocess_image_style to alter the style name to use:

/**
 * Implements hook_preprocess_HOOK for theme image_style.
 */
 function mymodule_preprocess_image_style(&$variables) {
   $style = mymodule_determine_style_to_use($variables);
   $variables['style_name'] = $style;
 }

Take care that you do not alter all image styles, but only those you want/need to change, so mymodule_determine_style_to_use() should e.g have a check on $variables['style_name'] being S1 or S2.

0

Install and configure Image Style Access module.

Allows granular access control to images and image style derivatives.This module provides access control for image files. Each access configuration can be set to allow or deny access to images and their derivatives by:

File source (scheme), Base image file location and Image style.

1
  • I think this doesn't work. When access is denied no image is displayed rather than the correct image.
    – penname
    Dec 28, 2015 at 19:35
0

I have learnt that this can be accomplished without code using https://www.drupal.org/project/ffc

Thank you to those who posted answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.