6

In Drupal 7 I used hook_views_pre_render() to update the image style for specific results. I'm trying to do the same for a view in Drupal 8 but I don't have the same options available in the field.

An example of the code I used before: $view->result[4]->field_field_image[0]['rendered']['#image_style'] = 'image_style_name';

There's no longer a 'rendered' array, just an ImageItem object with the target_id, title, width and height.

1 Answer 1

1

The bad news is that you can't use that approach anymore. Due to the performance improvements like this one, fields are all rendered via #pre_render callbacks, and run through the same build process as normal entity rendering.

The good news is that hook_entity_display_build_alter() will run, the very same hook that runs for displaying an entity.

Views doesn't pass any additional context to this hook. Depending on how you were deciding which one to alter, you may still be able to accomplish this.

1
  • Unfortunately I wasn't able to accomplish the thing I wanted because I needed more context from views but thanks for the detailed explanation :)
    – joekers
    Jan 19, 2017 at 11:41

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.