Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Assigns a random style name to each image
- function <MODULE_NAME>_views_pre_render(&$view)
- {
- if($view->name == 'SOME VIEW')
- {
- $styles = array('thumbnail', 'medium', 'large');
- foreach($view->result as &$result)
- {
- $result->field_field_image[0]['rendered']['#image_style'] = $styles[array_rand($styles)];
- }
- }
- }
- function <MODULE_NAME>_views_pre_render(ViewExecutable $view)
- {
- if($view->id() == 'SOME VIEW')
- {
- $styles = array('thumbnail', 'medium', 'large');
- foreach($view->result as &$result)
- {
- $image = $result->_entity->get("field_media_image");
- $image->SOME_FUNCTION('#style_name') = $styles[array_rand($styles)];
- }
- }
- }
- function <TEMPLATE_NAME>_preprocess_image_formatter(&$variables) {
- $styles = array('thumbnail', 'medium', 'large');
- if ($variables['image']['#style_name'] === 'medium') {
- $variables['image']['#style_name'] = $styles[array_rand($styles)];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement