0

I have a view with an image field and other fields, and I need to link the rendered image, not the content which is one of the configuration choice, but on another computed filtered view. I think that I should use my_theme_preprocess_views_view_field_myviewname to catch this field, using it's name as selector then wrap it with the computed link, but didn't find how to do it.

To clarify my question, the image in this view is normally displayed, and I "dynamically" create a link to another view which is not related to the image. I wrote a function (in my template) to compute this link, and I need to know how to add this link to the image field within my_theme_preprocess_views_view_field_myviewname(&vars). The preprocess function is executed several times to build the view, I tried to use var_dump(vars) to see where is the image field, but it generates a too huge amount of data.

8
  • 2
    You can use the "Rewrite Results" option in the view configuration for the image field. If you extend your question with more details, I can post an answer how to do it.
    – Elin Y.
    Commented Dec 15, 2015 at 11:08
  • Rewrite results does not let me what I want, I added more details as you suggested.
    – Pierre_C
    Commented Dec 15, 2015 at 12:37
  • Why rewriting results is not an option? Is your view setup to show fields or content or anything else?
    – MrUpsidown
    Commented Dec 15, 2015 at 13:44
  • @MrUpsidown: rewriting is not an option at least because I need to get/extract the contextual filter values that have been given as parameters to call this view. Then I insert other parameters like computed page number to build the new link for the image.
    – Pierre_C
    Commented Dec 15, 2015 at 15:38
  • Don't you have access to the contextual filter value in the replacement patterns?
    – MrUpsidown
    Commented Dec 15, 2015 at 16:00

2 Answers 2

0

As per your question, I assume that you want the image link to open the image in existing/new tab. For this you can add a relationship of 'File Usage : File'.Post that you get the file path field in the fields section of the view. Add that file path field and in the rewrite result section or in template file you can create tag with the required image. PS: In field image setting select noting in link image to setting.

4
  • In fact no, the link points to another view, which is a "contextual filtered view" that allow to be dynamically created.
    – Pierre_C
    Commented Dec 15, 2015 at 12:43
  • In the view template file you can wrap the image field with your computed link. Commented Dec 15, 2015 at 12:55
  • Yes but how? The function my_theme_preprocess_views_view_field_myviewname(&vars) is called for each fields and I didn't find the field name within "vars".
    – Pierre_C
    Commented Dec 15, 2015 at 13:35
  • Can you please send me your contextual filter view url. Commented Dec 16, 2015 at 13:06
0

After some more search/tests and your help here is the solution I used to do it. In my theme template.php I added

function MyTHEME_preprocess_views_view_field__VIEWNAME__page(&$vars) {
  $view = $vars['view'];
  $field = $vars['field'];

  // field is an object of type views_handler_field_node

  if ((isset($field)) && ($field->field == 'my_image_field_name' )) {

     // create a string like <a href="" >
     $myLink = myFunctionToBuildLink($view);

     $vars['output'] = $myLink . $vars['output'] . '</a>';
  }
}

Now I have the right link to the specific view and page I wanted. The "__page" at the end of the function name is because I use a view with display page.

Your Answer

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

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